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

absensi_score: {
        type: DataTypes.INTEGER,
      
      

      },

disiplin_score: {
        type: DataTypes.INTEGER,
      
      

      },

produktif_score: {
        type: DataTypes.INTEGER,
      
      

      },

attitude_score: {
        type: DataTypes.INTEGER,
      
      

      },

sop_score: {
        type: DataTypes.INTEGER,
      
      

      },

final_score: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

scored_at: {
        type: DataTypes.DATE,
      
      

      },

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

  kpi_scores.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.kpi_scores.belongsTo(db.employees, {
      as: 'employee',
      foreignKey: {
        name: 'employeeId',
      },
      constraints: false,
    });

    db.kpi_scores.belongsTo(db.kpi_periods, {
      as: 'kpi_period',
      foreignKey: {
        name: 'kpi_periodId',
      },
      constraints: false,
    });

    db.kpi_scores.belongsTo(db.outlets, {
      as: 'outlet',
      foreignKey: {
        name: 'outletId',
      },
      constraints: false,
    });

    db.kpi_scores.belongsTo(db.users, {
      as: 'scored_by_user',
      foreignKey: {
        name: 'scored_by_userId',
      },
      constraints: false,
    });

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




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

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



  return kpi_scores;
};


