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

document_date: {
        type: DataTypes.DATE,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"lab_result",


"imaging",


"doctor_letter",


"hospital_summary",


"pathology",


"insurance",


"medical_certificate",


"other"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.lab_documents.belongsTo(db.healthcare_providers, {
      as: 'ordered_by_provider',
      foreignKey: {
        name: 'ordered_by_providerId',
      },
      constraints: false,
    });



    db.lab_documents.hasMany(db.file, {
      as: 'file_attachments',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.lab_documents.getTableName(),
        belongsToColumn: 'file_attachments',
      },
    });


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

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



  return lab_documents;
};


