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

collected_at: {
        type: DataTypes.DATE,
      
      

      },

quantity: {
        type: DataTypes.INTEGER,
      
      

      },

broken_quantity: {
        type: DataTypes.INTEGER,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  egg_collections.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.egg_collections.belongsTo(db.poultry_lots, {
      as: 'poultry_lot',
      foreignKey: {
        name: 'poultry_lotId',
      },
      constraints: false,
    });

    db.egg_collections.belongsTo(db.users, {
      as: 'recorded_by_user',
      foreignKey: {
        name: 'recorded_by_userId',
      },
      constraints: false,
    });




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

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



  return egg_collections;
};


