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

room_number: {
        type: DataTypes.TEXT,
      
      

      },

ward_name: {
        type: DataTypes.TEXT,
      
      

      },

room_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"single",


"double",


"icu"

        ],

      },

price_per_day: {
        type: DataTypes.DECIMAL,
      
      

      },

capacity: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  inpatient_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.inpatient_rooms.hasMany(db.room_bookings, {
      as: 'room_bookings_room',
      foreignKey: {
          name: 'roomId',
      },
      constraints: false,
    });











//end loop






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

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



  return inpatient_rooms;
};


