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

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

    return State;
  }

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

module.exports = State;



