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

export interface PlanContentAttributes extends Optional<PlanContentInterface, 'id'> { }

export class PlanContent extends Model<PlanContentInterface, PlanContentAttributes> implements PlanContentInterface {
    public id!: number;
    public planId!: number;
    public languageId!: number;
    public name!: string;
    public description!: Text;
    public descriptionText!: Text;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof PlanContent {
        PlanContent.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                planId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-plan-content", comment: "plan identifier" },
                languageId: { type: DataTypes.BIGINT, allowNull: false, unique: "unique-plan-content", comment: "content language identifier" },
                name: { type: DataTypes.STRING, allowNull: false, comment: "plan name" },
                description: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "plan description html format" },
                descriptionText: { type: DataTypes.TEXT, allowNull: true, defaultValue: null, comment: "plan description text format" }
            },
            { 
                paranoid: true, 
                underscored: true, 
                sequelize, 
                tableName: 'plan_content', 
                timestamps: true,
                indexes: [
                ]
            }
        );
        return PlanContent;
    }

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