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

start_date: {
        type: DataTypes.DATE,
      
      

      },

end_date: {
        type: DataTypes.DATE,
      
      

      },

nightly_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

pricing_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"override",


"delta"

        ],

      },

delta_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  seasonal_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.seasonal_rates.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });

    db.seasonal_rates.belongsTo(db.room_types, {
      as: 'room_type',
      foreignKey: {
        name: 'room_typeId',
      },
      constraints: false,
    });

    db.seasonal_rates.belongsTo(db.rate_plans, {
      as: 'rate_plan',
      foreignKey: {
        name: 'rate_planId',
      },
      constraints: false,
    });

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




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

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



  return seasonal_rates;
};


