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

name: {
        type: DataTypes.TEXT,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

pricing_model: {
        type: DataTypes.ENUM,
      
      

        values: [

"per_night",


"per_person_per_night"

        ],

      },

cancellation_policy_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"flexible",


"moderate",


"strict",


"non_refundable",


"custom"

        ],

      },

cancellation_policy_text: {
        type: DataTypes.TEXT,
      
      

      },

min_stay_nights: {
        type: DataTypes.INTEGER,
      
      

      },

max_stay_nights: {
        type: DataTypes.INTEGER,
      
      

      },

release_days: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

is_refundable: {
        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,
    },
  );

  rate_plans.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity















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




    db.rate_plans.hasMany(db.bookings, {
      as: 'bookings_rate_plan',
      foreignKey: {
          name: 'rate_planId',
      },
      constraints: false,
    });













//end loop



    db.rate_plans.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });




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

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



  return rate_plans;
};


