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

export interface FaqContentAttributes extends Optional<FaqContentInterface, 'id'> { }

export class FaqContent extends Model<FaqContentInterface, FaqContentAttributes> implements FaqContentInterface {
    public id!: number;
    public faqId!: number;
    public languageId!: number;
    public question!: string;
    public answer!: Text;
    public answerText!: Text;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof FaqContent {
        FaqContent.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                faqId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-faq-content", comment: "faq identifier" },
                languageId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-faq-content", comment: "content language identifier" },
                question: { type: DataTypes.STRING, allowNull: false, comment: "faq question" },
                answer: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "faq answer" },
                answerText: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "faq answer" }
            },
            {
                paranoid: true,
                underscored: true,
                sequelize,
                tableName: 'faq_content',
                timestamps: true,
                indexes: [
                    { name: 'faq-search', fields: ['question', 'answer_text'], type: 'FULLTEXT' },
                    { name: 'faq-language', fields: ['language_id'] }
                ]
            }
        );
        return FaqContent;
    }

    public static associate(models: any) {
        FaqContent.belongsTo(models.Faq, { foreignKey: 'faqId', as: 'faq' });
        FaqContent.belongsTo(models.Language, { foreignKey: 'languageId', as: 'language' });
    }
}
