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

tested_at: {
        type: DataTypes.DATE,
      
      

      },

tests_performed: {
        type: DataTypes.TEXT,
      
      

      },

result_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"negative",


"positive",


"pending",


"inconclusive"

        ],

      },

results_notes: {
        type: DataTypes.TEXT,
      
      

      },

next_recommended_test_date: {
        type: DataTypes.DATE,
      
      

      },

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

  sti_tests.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.sti_tests.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.sti_tests.belongsTo(db.healthcare_providers, {
      as: 'clinic_provider',
      foreignKey: {
        name: 'clinic_providerId',
      },
      constraints: false,
    });




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

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



  return sti_tests;
};


