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

parameter: {
        type: DataTypes.TEXT,
      
      

      },

value: {
        type: DataTypes.DECIMAL,
      
      

      },

unit: {
        type: DataTypes.TEXT,
      
      

      },

confidence: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high"

        ],

      },

basis_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  design_criteria_items.associate = (db) => {

    db.design_criteria_items.belongsToMany(db.metallurgical_tests, {
      as: 'source_tests',
      foreignKey: {
        name: 'design_criteria_items_source_testsId',
      },
      constraints: false,
      through: 'design_criteria_itemsSource_testsMetallurgical_tests',
    });

    db.design_criteria_items.belongsToMany(db.metallurgical_tests, {
      as: 'source_tests_filter',
      foreignKey: {
        name: 'design_criteria_items_source_testsId',
      },
      constraints: false,
      through: 'design_criteria_itemsSource_testsMetallurgical_tests',
    });


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


































//end loop



    db.design_criteria_items.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.design_criteria_items.belongsTo(db.project_phases, {
      as: 'phase',
      foreignKey: {
        name: 'phaseId',
      },
      constraints: false,
    });

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




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

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



  return design_criteria_items;
};


