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

export interface EmailTemplateAttributes {
    id: string;
    templateCode: string;
    description: string;
    subject: string;
    body: string;
    placeholders: any; // JSON array of strings
    isActive: boolean;
}

export interface EmailTemplateInstance extends Model<EmailTemplateAttributes>, EmailTemplateAttributes { }

export default (sequelize: Sequelize) => {
    const EmailTemplate = sequelize.define<EmailTemplateInstance>('EmailTemplate', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        templateCode: {
            type: DataTypes.STRING,
            unique: true,
            allowNull: false
        },
        description: {
            type: DataTypes.STRING,
            allowNull: false
        },
        subject: {
            type: DataTypes.STRING,
            allowNull: false
        },
        body: {
            type: DataTypes.TEXT,
            allowNull: false
        },
        placeholders: {
            type: DataTypes.JSON,
            defaultValue: []
        },
        isActive: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        }
    }, {
        tableName: 'email_templates',
        timestamps: true
    });

    return EmailTemplate;
};
