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

full_name: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

subject_ar: {
        type: DataTypes.TEXT,
      
      

      },

message_ar: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"replied",


"closed"

        ],

      },

received_at: {
        type: DataTypes.DATE,
      
      

      },

replied_at: {
        type: DataTypes.DATE,
      
      

      },

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

  inquiries.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.inquiries.belongsTo(db.contact_locations, {
      as: 'location',
      foreignKey: {
        name: 'locationId',
      },
      constraints: false,
    });

    db.inquiries.belongsTo(db.users, {
      as: 'assigned_to',
      foreignKey: {
        name: 'assigned_toId',
      },
      constraints: false,
    });




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

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



  return inquiries;
};


