import { Model, DataTypes, Sequelize } from 'sequelize';

export interface InterviewConfigAttributes {
    id: string;
    configType: 'KT_MATRIX' | 'LEVEL2_FEEDBACK' | 'LEVEL3_FEEDBACK';
    name: string;
    version: string;
    isActive: boolean;
}

export interface InterviewConfigInstance extends Model<InterviewConfigAttributes>, InterviewConfigAttributes { }

export default (sequelize: Sequelize) => {
    const InterviewConfig = sequelize.define<InterviewConfigInstance>('InterviewConfig', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        configType: {
            type: DataTypes.ENUM('KT_MATRIX', 'LEVEL2_FEEDBACK', 'LEVEL3_FEEDBACK'),
            allowNull: false
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        version: {
            type: DataTypes.STRING,
            allowNull: false
        },
        isActive: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        }
    }, {
        tableName: 'interview_configs',
        timestamps: true,
        indexes: [
            { fields: ['configType', 'isActive'] }
        ]
    });

    (InterviewConfig as any).associate = (models: any) => {
        InterviewConfig.hasMany(models.InterviewConfigItem, { foreignKey: 'configId', as: 'items' });
    };

    return InterviewConfig;
};
