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

reason: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"OPEN",


"UNDER_REVIEW",


"RESOLVED",


"REJECTED"

        ],

      },

resolution_notes: {
        type: DataTypes.TEXT,
      
      

      },

created_at_ts: {
        type: DataTypes.DATE,
      
      

      },

updated_at_ts: {
        type: DataTypes.DATE,
      
      

      },

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

  disputes.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.disputes.belongsTo(db.leads, {
      as: 'lead',
      foreignKey: {
        name: 'leadId',
      },
      constraints: false,
    });

    db.disputes.belongsTo(db.users, {
      as: 'opened_by_user',
      foreignKey: {
        name: 'opened_by_userId',
      },
      constraints: false,
    });




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

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



  return disputes;
};


