const { Model, DataTypes } = require('sequelize');

/**
 * Sick Model
 * Repräsentiert die sick-Tabelle (Krankmeldungen)
 */
class Sick extends Model {
  static initialize(sequelize) {
    Sick.init(
      {
        id: {
          type: DataTypes.BIGINT,
          primaryKey: true,
          autoIncrement: true,
          allowNull: false
        },
        version: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0
        },
        user_id: {
          type: DataTypes.BIGINT,
          allowNull: true,
          references: {
            model: 'user',
            key: 'id'
          }
        },
        first_day: {
          type: DataTypes.DATEONLY,
          allowNull: true
        },
        last_day: {
          type: DataTypes.DATEONLY,
          allowNull: true
        },
        sick_type_id: {
          type: DataTypes.BIGINT,
          allowNull: true,
          references: {
            model: 'sick_type',
            key: 'id'
          }
        }
      },
      {
        sequelize,
        tableName: 'sick',
        timestamps: false,
        indexes: [
          {
            name: 'fk_sick_user',
            fields: ['user_id']
          },
          {
            name: 'fk_sick_sick_type',
            fields: ['sick_type_id']
          }
        ]
      }
    );

    return Sick;
  }
}

module.exports = Sick;



