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

fed_at: {
        type: DataTypes.DATE,
      
      

      },

quantity_kg: {
        type: DataTypes.DECIMAL,
      
      

      },

feeding_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"manual",


"auto_feeder",


"broadcast",


"tray",


"other"

        ],

      },

appetite: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"normal",


"high"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  feeding_logs.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.feeding_logs.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.feeding_logs.belongsTo(db.batches, {
      as: 'batch',
      foreignKey: {
        name: 'batchId',
      },
      constraints: false,
    });

    db.feeding_logs.belongsTo(db.feed_products, {
      as: 'feed_product',
      foreignKey: {
        name: 'feed_productId',
      },
      constraints: false,
    });

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

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




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

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



  return feeding_logs;
};


