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

cost_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"actual",


"standard"

        ],

      },

material_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

labor_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

overhead_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

subcontract_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

total_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

calculated_at: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.production_costs.belongsTo(db.users, {
      as: 'calculated_by',
      foreignKey: {
        name: 'calculated_byId',
      },
      constraints: false,
    });




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

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



  return production_costs;
};


