"use strict";

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable("EmailTemplates", {
      id: {
        allowNull: false,
        primaryKey: true,
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
      },
      slug: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true,
        comment: "Unique identifier like 'merchant_welcome'",
      },
      name: {
        type: Sequelize.STRING,
        allowNull: false,
        comment: "Human readable name",
      },
      subject: {
        type: Sequelize.STRING,
        allowNull: false,
      },
      bodyHtml: {
        type: Sequelize.TEXT("long"),
        allowNull: false,
        comment: "HTML body content. Variables can be interpolated using {{variableName}}",
      },
      availableVariables: {
        type: Sequelize.STRING,
        allowNull: true,
        comment: "Comma separated list of available variables, e.g., '{{businessName}}, {{otp}}'",
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
      },
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable("EmailTemplates");
  },
};
