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

case_number: {
        type: DataTypes.TEXT,
      
      

      },

diagnosis: {
        type: DataTypes.TEXT,
      
      

      },

procedure_details: {
        type: DataTypes.TEXT,
      
      

      },

recommendations: {
        type: DataTypes.TEXT,
      
      

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"completed",


"sent_to_doctor"

        ],

      },

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

  endoscopy_cases.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.endoscopy_cases.belongsTo(db.visits, {
      as: 'visit',
      foreignKey: {
        name: 'visitId',
      },
      constraints: false,
    });

    db.endoscopy_cases.belongsTo(db.doctors, {
      as: 'doctor',
      foreignKey: {
        name: 'doctorId',
      },
      constraints: false,
    });



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


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

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



  return endoscopy_cases;
};


