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

sampled_at: {
        type: DataTypes.DATE,
      
      

      },

temperature_c: {
        type: DataTypes.DECIMAL,
      
      

      },

ph: {
        type: DataTypes.DECIMAL,
      
      

      },

dissolved_oxygen_mg_l: {
        type: DataTypes.DECIMAL,
      
      

      },

salinity_ppt: {
        type: DataTypes.DECIMAL,
      
      

      },

ammonia_mg_l: {
        type: DataTypes.DECIMAL,
      
      

      },

nitrite_mg_l: {
        type: DataTypes.DECIMAL,
      
      

      },

nitrate_mg_l: {
        type: DataTypes.DECIMAL,
      
      

      },

turbidity_ntu: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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

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

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




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

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



  return water_quality_logs;
};


