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 notification_templates = sequelize.define(
    'notification_templates',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"email",


"whatsapp",


"sms"

        ],

      },

event_key: {
        type: DataTypes.ENUM,
      
      

        values: [

"booking_created",


"payment_succeeded",


"booking_confirmed",


"booking_cancelled",


"pickup_reminder",


"dropoff_reminder",


"checkin_completed",


"invoice_issued"

        ],

      },

subject_template: {
        type: DataTypes.TEXT,
      
      

      },

body_template: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  notification_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.notification_templates.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

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




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

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



  return notification_templates;
};


