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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"order",


"clinical_notes",


"imaging_report",


"labs",


"prior_auth_form",


"denial_letter",


"appeal_letter",


"insurance_card",


"other"

        ],

      },

source_channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"upload",


"fax",


"email",


"portal_download",


"integration",


"other"

        ],

      },

storage_key: {
        type: DataTypes.TEXT,
      
      

      },

original_filename: {
        type: DataTypes.TEXT,
      
      

      },

checksum: {
        type: DataTypes.TEXT,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

version_number: {
        type: DataTypes.INTEGER,
      
      

      },

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

  case_documents.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity























    db.case_documents.hasMany(db.ai_jobs, {
      as: 'ai_jobs_case_document',
      foreignKey: {
          name: 'case_documentId',
      },
      constraints: false,
    });








//end loop



    db.case_documents.belongsTo(db.authorization_cases, {
      as: 'authorization_case',
      foreignKey: {
        name: 'authorization_caseId',
      },
      constraints: false,
    });

    db.case_documents.belongsTo(db.users, {
      as: 'uploaded_by_user',
      foreignKey: {
        name: 'uploaded_by_userId',
      },
      constraints: false,
    });

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




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

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



  return case_documents;
};


