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

study_number: {
        type: DataTypes.TEXT,
      
      

      },

report_summary: {
        type: DataTypes.TEXT,
      
      

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"completed",


"cancelled"

        ],

      },

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

  radiology_studies.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.radiology_studies.belongsTo(db.orders, {
      as: 'order',
      foreignKey: {
        name: 'orderId',
      },
      constraints: false,
    });

    db.radiology_studies.belongsTo(db.radiology_types, {
      as: 'study_type',
      foreignKey: {
        name: 'study_typeId',
      },
      constraints: false,
    });

    db.radiology_studies.belongsTo(db.users, {
      as: 'technician',
      foreignKey: {
        name: 'technicianId',
      },
      constraints: false,
    });



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


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

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



  return radiology_studies;
};


