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

export interface PromotionContentAttributes extends Optional<PromotionContentInterface, 'id'> { }

export class PromotionContent extends Model<PromotionContentInterface, PromotionContentAttributes> implements PromotionContentInterface {
    public id!: number;
    public promotionId!: 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 PromotionContent {
        PromotionContent.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                promotionId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-promotion-content", comment: "Promotion identifier" },
                languageId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-promotion-content", comment: "content language identifier" },
                title: { type: DataTypes.STRING, allowNull: false, comment: "Promotion title" },
                description: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "Promotion description html format" },
                descriptionText: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "Promotion description text format" }
            },
            { 
                paranoid: true, 
                underscored: true, 
                sequelize, 
                tableName: 'promotion_content', 
                timestamps: true,
                indexes: [
                ]
            }
        );
        return PromotionContent;
    }

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