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

export interface QuestionnaireOptionAttributes {
    id: string;
    questionId: string;
    optionText: string;
    score: number;
    order: number;
}

export interface QuestionnaireOptionInstance extends Model<QuestionnaireOptionAttributes>, QuestionnaireOptionAttributes { }

export default (sequelize: Sequelize) => {
    const QuestionnaireOption = sequelize.define<QuestionnaireOptionInstance>('QuestionnaireOption', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        questionId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'questionnaire_questions',
                key: 'id'
            }
        },
        optionText: {
            type: DataTypes.STRING,
            allowNull: false
        },
        score: {
            type: DataTypes.INTEGER,
            defaultValue: 0
        },
        order: {
            type: DataTypes.INTEGER,
            defaultValue: 0
        }
    }, {
        tableName: 'questionnaire_options',
        timestamps: true
    });

    (QuestionnaireOption as any).associate = (models: any) => {
        QuestionnaireOption.belongsTo(models.QuestionnaireQuestion, { foreignKey: 'questionId', as: 'question' });
    };

    return QuestionnaireOption;
};
