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

block_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"blackout",


"maintenance",


"owner_hold",


"reservation_hold"

        ],

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

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

  unit_availability_blocks.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.unit_availability_blocks.belongsTo(db.units, {
      as: 'unit',
      foreignKey: {
        name: 'unitId',
      },
      constraints: false,
    });

    db.unit_availability_blocks.belongsTo(db.reservations, {
      as: 'reservation',
      foreignKey: {
        name: 'reservationId',
      },
      constraints: false,
    });

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




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

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



  return unit_availability_blocks;
};


