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

export interface SeaQAQuestionCategoryAttributes {
    id: number;
    questionId: number;
    categoryId: number;
}



export interface SeaQAQuestionCategoryCreationAttributes extends Optional<SeaQAQuestionCategoryAttributes, 'id'> {}

export class SeaQAQuestionCategory extends Model<SeaQAQuestionCategoryAttributes, SeaQAQuestionCategoryCreationAttributes> implements SeaQAQuestionCategoryAttributes {
    public id!: number;
    public questionId!: number;
    public categoryId!: number;

    static initModel(sequelize: Sequelize): typeof SeaQAQuestionCategory {


        SeaQAQuestionCategory.init({
            id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
            questionId: { type: DataTypes.BIGINT, allowNull: false, comment: "question reference" },
            categoryId: { type: DataTypes.BIGINT, allowNull: false, comment: "category reference" }
        }, {
            sequelize,
            tableName: 'sea_qa_question_categories',
            timestamps: false,
            underscored: true,


            indexes: [
                { name: 'sea_qa_question_category_index', fields: ['question_id', 'category_id'] }
            ]
        });
        return SeaQAQuestionCategory;
    }

    public static associate(models: any) {
        SeaQAQuestionCategory.belongsTo(models.SeaQAQuestion, { foreignKey: 'questionId' });
        SeaQAQuestionCategory.belongsTo(models.Category, { foreignKey: 'categoryId' });
    }
}
