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

test_number: {
        type: DataTypes.TEXT,
      
      

      },

result_text: {
        type: DataTypes.TEXT,
      
      

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  ecg_stress_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.ecg_stress_tests.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

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



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


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

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



  return ecg_stress_tests;
};


