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

employment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"employee",


"contractor",


"freelancer"

        ],

      },

seniority: {
        type: DataTypes.ENUM,
      
      

        values: [

"junior",


"mid",


"senior",


"lead",


"principal"

        ],

      },

hourly_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

rate_currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"USD",


"CDF",


"EUR",


"XAF",


"XOF"

        ],

      },

weekly_capacity_hours: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  team_members.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity


























    db.team_members.hasMany(db.team_member_skills, {
      as: 'team_member_skills_team_member',
      foreignKey: {
          name: 'team_memberId',
      },
      constraints: false,
    });


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


    db.team_members.hasMany(db.leave_requests, {
      as: 'leave_requests_team_member',
      foreignKey: {
          name: 'team_memberId',
      },
      constraints: false,
    });



















//end loop



    db.team_members.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.team_members.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return team_members;
};


