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

disposition_name: {
        type: DataTypes.TEXT,
      
      

      },

disposition_code: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"use_as_is",


"rework",


"repair",


"scrap",


"return_to_supplier",


"sort"

        ],

      },

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

      },

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

  disposition_codes.associate = (db) => {


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
































    db.disposition_codes.hasMany(db.nonconformances, {
      as: 'nonconformances_disposition_code',
      foreignKey: {
          name: 'disposition_codeId',
      },
      constraints: false,
    });






//end loop






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

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



  return disposition_codes;
};


