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

value_decimal: {
        type: DataTypes.DECIMAL,
      
      

      },

value_int: {
        type: DataTypes.INTEGER,
      
      

      },

value_boolean: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

value_text: {
        type: DataTypes.TEXT,
      
      

      },

value_enum: {
        type: DataTypes.ENUM,
      
      

        values: [

"na",


"low",


"medium",


"high"

        ],

      },

quality_flag: {
        type: DataTypes.ENUM,
      
      

        values: [

"ok",


"suspect",


"invalid"

        ],

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

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

  observations.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.observations.belongsTo(db.observation_events, {
      as: 'observation_event',
      foreignKey: {
        name: 'observation_eventId',
      },
      constraints: false,
    });

    db.observations.belongsTo(db.traits, {
      as: 'trait',
      foreignKey: {
        name: 'traitId',
      },
      constraints: false,
    });

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




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

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



  return observations;
};


