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

export interface SeaQAAnswerContentAttributes extends Optional<SeaQAAnswerContentInterface, 'id'> { }

export class SeaQAAnswerContent extends Model<SeaQAAnswerContentInterface, SeaQAAnswerContentAttributes> implements SeaQAAnswerContentInterface {
    public id!: number;
    public answerId!: number;
    public languageId!: number;
    public body!: string;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof SeaQAAnswerContent {
        SeaQAAnswerContent.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                answerId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-sea-qa-answer-content", comment: "answer identifier" },
                languageId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-sea-qa-answer-content", comment: "content language identifier" },
                body: { type: DataTypes.TEXT('medium'), allowNull: false, comment: "answer body" }
            },
            {
                paranoid: true,
                underscored: true,
                sequelize,
                tableName: 'sea_qa_answer_content',
                timestamps: true,
                indexes: [
                    { name: 'sea-qa-answer-search', fields: ['body'], type: 'FULLTEXT' },
                    { name: 'sea-qa-answer-language', fields: ['language_id'] }
                ]
            }
        );
        return SeaQAAnswerContent;
    }

    public static associate(models: any) {
        SeaQAAnswerContent.belongsTo(models.SeaQAAnswer, { foreignKey: 'answerId', as: 'answer' });
        SeaQAAnswerContent.belongsTo(models.Language, { foreignKey: 'languageId', as: 'language' });
    }
}
