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

ct_number: {
        type: DataTypes.TEXT,
      
      

      },

result_text: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"completed",


"cancelled"

        ],

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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

    db.ct_studies.belongsTo(db.ct_types, {
      as: 'ct_type',
      foreignKey: {
        name: 'ct_typeId',
      },
      constraints: false,
    });



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


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

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



  return ct_studies;
};


