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

export interface ActivityContentAttributes extends Optional<ActivityContentInterface, 'id'> { }

export class ActivityContent extends Model<ActivityContentInterface, ActivityContentAttributes> implements ActivityContentInterface {
    public id!: number;
    public activityId!: number;
    public languageId!: number;
    public title!: string;
    public description!: Text;
    public descriptionText!: Text;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof ActivityContent {
        ActivityContent.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                activityId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-activity-content", comment: "activity identifier" },
                languageId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-activity-content", comment: "content language identifier" },
                title: { type: DataTypes.STRING, allowNull: false, comment: "activity title" },
                description: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "activity description html format" },
                descriptionText: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "activity description text format" }
            },
            {
                paranoid: true,
                underscored: true,
                sequelize,
                tableName: 'activity_content',
                timestamps: true,
                indexes: [
                    { name: 'activity-search', fields: ['title', 'description_text'], type: 'FULLTEXT' },
                    { name: 'activity-language', fields: ['language_id'] }
                ]
            }
        );
        return ActivityContent;
    }

    public static associate(models: any) {
        ActivityContent.belongsTo(models.Language, { foreignKey: 'languageId', as: 'language' });
        ActivityContent.belongsTo(models.Activity, { foreignKey: 'activityId', as: 'activity' });
    }
}
