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

pond_name: {
        type: DataTypes.TEXT,
      
      

      },

pond_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"earthen",


"lined",


"tank",


"cage",


"raceway",


"other"

        ],

      },

area_sq_m: {
        type: DataTypes.DECIMAL,
      
      

      },

avg_depth_m: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"maintenance",


"inactive"

        ],

      },

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

  ponds.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity











    db.ponds.hasMany(db.batches, {
      as: 'batches_pond',
      foreignKey: {
          name: 'pondId',
      },
      constraints: false,
    });






    db.ponds.hasMany(db.water_quality_logs, {
      as: 'water_quality_logs_pond',
      foreignKey: {
          name: 'pondId',
      },
      constraints: false,
    });

















//end loop



    db.ponds.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.ponds.belongsTo(db.tenant_locations, {
      as: 'location',
      foreignKey: {
        name: 'locationId',
      },
      constraints: false,
    });

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




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

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



  return ponds;
};


