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

document_name: {
        type: DataTypes.TEXT,
      
      

      },

document_date: {
        type: DataTypes.DATE,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"doctor_letter",


"hospital_discharge",


"specialist_report",


"scan_result",


"surgical_report",


"pathology_report",


"insurance",


"medical_certificate",


"other"

        ],

      },

issuing_institution: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

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



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


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

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



  return health_vault_documents;
};


