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

export interface InterviewConfigItemOptionAttributes {
    id: string;
    itemId: string;
    optionLabel: string;
    optionValue: string;
    score: number;
    order: number;
}

export interface InterviewConfigItemOptionInstance extends Model<InterviewConfigItemOptionAttributes>, InterviewConfigItemOptionAttributes { }

export default (sequelize: Sequelize) => {
    const InterviewConfigItemOption = sequelize.define<InterviewConfigItemOptionInstance>('InterviewConfigItemOption', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        itemId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'interview_config_items',
                key: 'id'
            }
        },
        optionLabel: {
            type: DataTypes.STRING,
            allowNull: false
        },
        optionValue: {
            type: DataTypes.STRING,
            allowNull: false
        },
        score: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            defaultValue: 0
        },
        order: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 1
        }
    }, {
        tableName: 'interview_config_item_options',
        timestamps: true
    });

    (InterviewConfigItemOption as any).associate = (models: any) => {
        InterviewConfigItemOption.belongsTo(models.InterviewConfigItem, { foreignKey: 'itemId', as: 'item' });
    };

    return InterviewConfigItemOption;
};
