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

/**
 * Holiday Model
 * Repräsentiert die holiday-Tabelle
 */
class Holiday extends Model {
  static initialize(sequelize) {
    Holiday.init(
      {
        id: {
          type: DataTypes.BIGINT,
          primaryKey: true,
          autoIncrement: true,
          allowNull: false
        },
        version: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0
        },
        date: {
          type: DataTypes.DATEONLY,
          allowNull: true
        },
        hours: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 8
        },
        description: {
          type: DataTypes.TEXT,
          allowNull: false
        }
      },
      {
        sequelize,
        tableName: 'holiday',
        timestamps: false
      }
    );

    return Holiday;
  }

  /**
   * Definiert Assoziationen mit anderen Models
   */
  static associate(models) {
    // Holiday hat viele States (Many-to-Many über HolidayState)
    Holiday.belongsToMany(models.State, {
      through: models.HolidayState,
      foreignKey: 'holiday_id',
      otherKey: 'state_id',
      as: 'states'
    });
  }
}

module.exports = Holiday;



