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

planted_at: {
        type: DataTypes.DATE,
      
      

      },

estimated_harvest_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planted",


"growing",


"ready",


"withered",


"harvested"

        ],

      },

quantity_planted: {
        type: DataTypes.INTEGER,
      
      

      },

watered_today: {
        type: DataTypes.INTEGER,
      
      

      },

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

  plantings.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.plantings.belongsTo(db.farm_plots, {
      as: 'farm_plot',
      foreignKey: {
        name: 'farm_plotId',
      },
      constraints: false,
    });

    db.plantings.belongsTo(db.crops, {
      as: 'crop',
      foreignKey: {
        name: 'cropId',
      },
      constraints: false,
    });




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

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



  return plantings;
};


