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

rule_name: {
        type: DataTypes.TEXT,
      
      

      },

rule_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"geofence_access",


"local_priority",


"supply_routing"

        ],

      },

center_latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

center_longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

radius_meters: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"inactive"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  geo_rules.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.geo_rules.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return geo_rules;
};


