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,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

price_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

min_stay_nights: {
        type: DataTypes.INTEGER,
      
      

      },

max_stay_nights: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

      },

is_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.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.users, {
      as: 'createdBy',
    });

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



  return seasonal_rates;
};


