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

scheduled_for: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"in_progress",


"completed",


"cancelled"

        ],

      },

task_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"cleaning",


"inspection",


"turndown",


"linen_change",


"deep_clean"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  housekeeping_tasks.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.housekeeping_tasks.belongsTo(db.hotels, {
      as: 'hotel',
      foreignKey: {
        name: 'hotelId',
      },
      constraints: false,
    });

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

    db.housekeeping_tasks.belongsTo(db.staff_profiles, {
      as: 'assigned_staff_profile',
      foreignKey: {
        name: 'assigned_staff_profileId',
      },
      constraints: false,
    });

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




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

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



  return housekeeping_tasks;
};


