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

stream_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"solids",


"slurry",


"solution",


"air",


"recycle"

        ],

      },

mass_flow_tph: {
        type: DataTypes.DECIMAL,
      
      

      },

water_flow_m3h: {
        type: DataTypes.DECIMAL,
      
      

      },

solids_pct: {
        type: DataTypes.DECIMAL,
      
      

      },

au_grade_gpt: {
        type: DataTypes.DECIMAL,
      
      

      },

au_recovery_pct: {
        type: DataTypes.DECIMAL,
      
      

      },

components_json: {
        type: DataTypes.TEXT,
      
      

      },

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

  flowsheet_streams.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.flowsheet_streams.belongsTo(db.flowsheets, {
      as: 'flowsheet',
      foreignKey: {
        name: 'flowsheetId',
      },
      constraints: false,
    });

    db.flowsheet_streams.belongsTo(db.flowsheet_nodes, {
      as: 'source_node',
      foreignKey: {
        name: 'source_nodeId',
      },
      constraints: false,
    });

    db.flowsheet_streams.belongsTo(db.flowsheet_nodes, {
      as: 'target_node',
      foreignKey: {
        name: 'target_nodeId',
      },
      constraints: false,
    });

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




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

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



  return flowsheet_streams;
};


