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

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

day_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"weekday",


"weekend",


"holiday",


"any"

        ],

      },

rate_override: {
        type: DataTypes.DECIMAL,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  rate_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.rate_rules.belongsTo(db.rate_plans, {
      as: 'rate_plan',
      foreignKey: {
        name: 'rate_planId',
      },
      constraints: false,
    });

    db.rate_rules.belongsTo(db.vehicle_categories, {
      as: 'category',
      foreignKey: {
        name: 'categoryId',
      },
      constraints: false,
    });

    db.rate_rules.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

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




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

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



  return rate_rules;
};


