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

export interface TestimonialContentAttributes extends Optional<TestimonialContentInterface, 'id'> { }

export class TestimonialContent extends Model<TestimonialContentInterface, TestimonialContentAttributes> implements TestimonialContentInterface {
    public id!: number;
    public testimonialId!: number;
    public languageId!: number;
    public content!: Text | null;

    static initModel(sequelize: Sequelize): typeof TestimonialContent {
        TestimonialContent.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                testimonialId: { type: DataTypes.BIGINT, allowNull: false, comment: "testimonial identifier" },
                languageId: { type: DataTypes.BIGINT, allowNull: false, comment: "language identifier" },
                content: { type: DataTypes.TEXT, allowNull: false, comment: "testimonial description" },
            },
            {
                underscored: true,
                sequelize,
                tableName: 'testimonial_content',
                timestamps: false,
                indexes: [
                    { name: 'testimonial-content-index', fields: ['testimonial_id', 'language_id'], unique: true },
                    { name: 'testimonial-content-search-index', type: 'FULLTEXT', fields: ['content'] }
                ]
            }
        );
        return TestimonialContent;
    }

    public static associate(models: any) {
        TestimonialContent.belongsTo(models.Testimonial, { foreignKey: 'testimonialId', as: 'testimonial' });
        TestimonialContent.belongsTo(models.Language, { foreignKey: 'languageId', as: 'language' });
    }
}
