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

name: {
        type: DataTypes.TEXT,
      
      

      },

classification: {
        type: DataTypes.ENUM,
      
      

        values: [

"inferred",


"indicated",


"measured",


"unknown"

        ],

      },

ore_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"oxide",


"transition",


"fresh",


"refractory",


"preg_robbing",


"high_clay",


"other"

        ],

      },

head_grade_au_gpt: {
        type: DataTypes.DECIMAL,
      
      

      },

tonnage_mt: {
        type: DataTypes.DECIMAL,
      
      

      },

mineralogy_json: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  ore_bodies.associate = (db) => {


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










    db.ore_bodies.hasMany(db.samples, {
      as: 'samples_ore_body',
      foreignKey: {
          name: 'ore_bodyId',
      },
      constraints: false,
    });

























//end loop



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

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




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

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



  return ore_bodies;
};


