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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"active",


"inactive"

        ],

      },

revenue_share_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

effective_from: {
        type: DataTypes.DATE,
      
      

      },

effective_to: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  tenant_partnerships.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.tenant_partnerships.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.tenant_partnerships.belongsTo(db.partners, {
      as: 'partner',
      foreignKey: {
        name: 'partnerId',
      },
      constraints: false,
    });

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




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

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



  return tenant_partnerships;
};


