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

booking_number: {
        type: DataTypes.TEXT,
      
      

      },

admission_date: {
        type: DataTypes.DATE,
      
      

      },

discharge_date: {
        type: DataTypes.DATE,
      
      

      },

days: {
        type: DataTypes.INTEGER,
      
      

      },

price_per_day: {
        type: DataTypes.DECIMAL,
      
      

      },

total_price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  room_bookings.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.room_bookings.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

    db.room_bookings.belongsTo(db.inpatient_rooms, {
      as: 'room',
      foreignKey: {
        name: 'roomId',
      },
      constraints: false,
    });

    db.room_bookings.belongsTo(db.nursing_staff, {
      as: 'supervising_nurse',
      foreignKey: {
        name: 'supervising_nurseId',
      },
      constraints: false,
    });

    db.room_bookings.belongsTo(db.doctors, {
      as: 'supervising_doctor',
      foreignKey: {
        name: 'supervising_doctorId',
      },
      constraints: false,
    });




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

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



  return room_bookings;
};


