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

rate_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"nightly",


"monthly"

        ],

      },

rate_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

valid_from: {
        type: DataTypes.DATE,
      
      

      },

valid_until: {
        type: DataTypes.DATE,
      
      

      },

minimum_stay_nights: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.negotiated_rates.belongsTo(db.properties, {
      as: 'property',
      foreignKey: {
        name: 'propertyId',
      },
      constraints: false,
    });

    db.negotiated_rates.belongsTo(db.unit_types, {
      as: 'unit_type',
      foreignKey: {
        name: 'unit_typeId',
      },
      constraints: false,
    });




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

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



  return negotiated_rates;
};


