const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const email_templates = sequelize.define(
    'email_templates',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

template_key: {
        type: DataTypes.ENUM,
      
      

        values: [

"welcome",


"password_reset",


"invoice_sent",


"ticket_assigned",


"deal_stage_changed",


"timesheet_reminder",


"ticket_resolution_survey"

        ],

      },

subject_fr: {
        type: DataTypes.TEXT,
      
      

      },

subject_en: {
        type: DataTypes.TEXT,
      
      

      },

body_fr: {
        type: DataTypes.TEXT,
      
      

      },

body_en: {
        type: DataTypes.TEXT,
      
      

      },

active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  email_templates.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity














































//end loop



    db.email_templates.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.email_templates.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




    db.email_templates.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.email_templates.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return email_templates;
};


