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

treatment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"vaccination",


"medication",


"vitamins",


"disinfection",


"other"

        ],

      },

product_name: {
        type: DataTypes.TEXT,
      
      

      },

dosage: {
        type: DataTypes.TEXT,
      
      

      },

administered_at: {
        type: DataTypes.DATE,
      
      

      },

next_due_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"done",


"missed",


"cancelled"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.treatments.belongsTo(db.users, {
      as: 'performed_by_user',
      foreignKey: {
        name: 'performed_by_userId',
      },
      constraints: false,
    });




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

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



  return treatments;
};


