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

cost_category: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

unit_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

install_factor: {
        type: DataTypes.DECIMAL,
      
      

      },

total_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

estimate_class: {
        type: DataTypes.ENUM,
      
      

        values: [

"class_5",


"class_4",


"class_3",


"class_2",


"class_1"

        ],

      },

basis_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  capex_items.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.capex_items.belongsTo(db.economic_models, {
      as: 'economic_model',
      foreignKey: {
        name: 'economic_modelId',
      },
      constraints: false,
    });

    db.capex_items.belongsTo(db.equipment_items, {
      as: 'equipment_item',
      foreignKey: {
        name: 'equipment_itemId',
      },
      constraints: false,
    });

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




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

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



  return capex_items;
};


