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

quantity_produced: {
        type: DataTypes.DECIMAL,
      
      

      },

lot_number: {
        type: DataTypes.TEXT,
      
      

      },

reported_at: {
        type: DataTypes.DATE,
      
      

      },

qa_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"released",


"rejected",


"on_hold"

        ],

      },

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

  production_outputs.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.production_outputs.belongsTo(db.production_orders, {
      as: 'production_order',
      foreignKey: {
        name: 'production_orderId',
      },
      constraints: false,
    });

    db.production_outputs.belongsTo(db.items, {
      as: 'item',
      foreignKey: {
        name: 'itemId',
      },
      constraints: false,
    });

    db.production_outputs.belongsTo(db.locations, {
      as: 'to_location',
      foreignKey: {
        name: 'to_locationId',
      },
      constraints: false,
    });

    db.production_outputs.belongsTo(db.users, {
      as: 'reported_by',
      foreignKey: {
        name: 'reported_byId',
      },
      constraints: false,
    });




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

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



  return production_outputs;
};


