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

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

allocated_hours: {
        type: DataTypes.DECIMAL,
      
      

      },

allocation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"billable",


"non_billable"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  resource_allocations.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.resource_allocations.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.resource_allocations.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.resource_allocations.belongsTo(db.team_members, {
      as: 'team_member',
      foreignKey: {
        name: 'team_memberId',
      },
      constraints: false,
    });

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




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

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



  return resource_allocations;
};


