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

code: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

element_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"material",


"labor",


"overhead",


"subcontract"

        ],

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  cost_elements.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.cost_elements.belongsTo(db.users, {
      as: 'createdBy',
    });

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



  return cost_elements;
};


