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

room_number: {
        type: DataTypes.TEXT,
      
      

      },

floor: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"available",


"occupied",


"dirty",


"cleaning",


"inspected",


"out_of_service"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  rooms.associate = (db) => {


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



















    db.rooms.hasMany(db.reservations, {
      as: 'reservations_room',
      foreignKey: {
          name: 'roomId',
      },
      constraints: false,
    });








    db.rooms.hasMany(db.housekeeping_tasks, {
      as: 'housekeeping_tasks_room',
      foreignKey: {
          name: 'roomId',
      },
      constraints: false,
    });


    db.rooms.hasMany(db.maintenance_tickets, {
      as: 'maintenance_tickets_room',
      foreignKey: {
          name: 'roomId',
      },
      constraints: false,
    });








//end loop



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

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

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




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

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



  return rooms;
};


