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

event_time: {
        type: DataTypes.DATE,
      
      

      },

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"collected",


"sealed",


"shipped",


"received",


"prepared",


"subsampled",


"analyzed",


"stored",


"disposed"

        ],

      },

from_party: {
        type: DataTypes.TEXT,
      
      

      },

to_party: {
        type: DataTypes.TEXT,
      
      

      },

location: {
        type: DataTypes.TEXT,
      
      

      },

shipping_reference: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  chain_of_custody_events.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.chain_of_custody_events.belongsTo(db.samples, {
      as: 'sample',
      foreignKey: {
        name: 'sampleId',
      },
      constraints: false,
    });

    db.chain_of_custody_events.belongsTo(db.users, {
      as: 'recorded_by',
      foreignKey: {
        name: 'recorded_byId',
      },
      constraints: false,
    });

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




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

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



  return chain_of_custody_events;
};


