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

period_name: {
        type: DataTypes.TEXT,
      
      

      },

period_start: {
        type: DataTypes.DATE,
      
      

      },

period_end: {
        type: DataTypes.DATE,
      
      

      },

total_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

distribution_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"equal",


"weighted_by_position"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"locked",


"archived"

        ],

      },

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

  service_charge_pools.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.service_charge_pools.belongsTo(db.outlets, {
      as: 'outlet',
      foreignKey: {
        name: 'outletId',
      },
      constraints: false,
    });

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




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

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



  return service_charge_pools;
};


