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

name: {
        type: DataTypes.TEXT,
      
      

      },

legal_name: {
        type: DataTypes.TEXT,
      
      

      },

address_line1: {
        type: DataTypes.TEXT,
      
      

      },

address_line2: {
        type: DataTypes.TEXT,
      
      

      },

city: {
        type: DataTypes.TEXT,
      
      

      },

state_region: {
        type: DataTypes.TEXT,
      
      

      },

postal_code: {
        type: DataTypes.TEXT,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

website: {
        type: DataTypes.TEXT,
      
      

      },

timezone: {
        type: DataTypes.TEXT,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

default_tax_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

stripe_customer_reference: {
        type: DataTypes.TEXT,
      
      

      },

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

  hotels.associate = (db) => {


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







    db.hotels.hasMany(db.departments, {
      as: 'departments_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.staff_profiles, {
      as: 'staff_profiles_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.shifts, {
      as: 'shifts_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.room_types, {
      as: 'room_types_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.rooms, {
      as: 'rooms_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.guests, {
      as: 'guests_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.guest_documents, {
      as: 'guest_documents_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


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


    db.hotels.hasMany(db.seasonal_rates, {
      as: 'seasonal_rates_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.dynamic_pricing_rules, {
      as: 'dynamic_pricing_rules_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.sales_channels, {
      as: 'sales_channels_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.ota_connections, {
      as: 'ota_connections_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.reservations, {
      as: 'reservations_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.reservation_guests, {
      as: 'reservation_guests_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.stay_folios, {
      as: 'stay_folios_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.folio_items, {
      as: 'folio_items_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.payments, {
      as: 'payments_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.refunds, {
      as: 'refunds_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.invoices, {
      as: 'invoices_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.housekeeping_tasks, {
      as: 'housekeeping_tasks_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.maintenance_tickets, {
      as: 'maintenance_tickets_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.notifications, {
      as: 'notifications_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.booking_widgets, {
      as: 'booking_widgets_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.subscriptions, {
      as: 'subscriptions_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.audit_logs, {
      as: 'audit_logs_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });


    db.hotels.hasMany(db.daily_snapshots, {
      as: 'daily_snapshots_hotel',
      foreignKey: {
          name: 'hotelId',
      },
      constraints: false,
    });



//end loop



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




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

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



  return hotels;
};


