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

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"order_created",


"status_changed",


"payment_received",


"invoice_issued",


"custom"

        ],

      },

to_number: {
        type: DataTypes.TEXT,
      
      

      },

message_body: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"sent",


"failed"

        ],

      },

queued_at: {
        type: DataTypes.DATE,
      
      

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

provider_message_id: {
        type: DataTypes.TEXT,
      
      

      },

error_details: {
        type: DataTypes.TEXT,
      
      

      },

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

  whatsapp_notifications.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.whatsapp_notifications.belongsTo(db.repair_orders, {
      as: 'repair_order',
      foreignKey: {
        name: 'repair_orderId',
      },
      constraints: false,
    });




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

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



  return whatsapp_notifications;
};


