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 workers_comp_classes = sequelize.define(
    'workers_comp_classes',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      name: {
        type: DataTypes.TEXT,
      },
      percentage: {
        type: DataTypes.DECIMAL,
      },
      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  workers_comp_classes.associate = (db) => {
    db.workers_comp_classes.hasMany(db.job_logs, {
      as: 'job_logs_workers_comp_class',
      foreignKey: {
          name: 'workersCompClassId',
      },
      constraints: false,
    });

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

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

  return workers_comp_classes;
};
