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

provider_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"gp",


"specialist",


"cardiologist",


"endocrinologist",


"dietitian",


"physiotherapist",


"personal_trainer",


"sports_physician",


"gynaecologist",


"urologist",


"psychologist",


"psychiatrist",


"sleep_specialist",


"dentist",


"optometrist",


"other"

        ],

      },

provider_name: {
        type: DataTypes.TEXT,
      
      

      },

clinic_name: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

address: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  healthcare_providers.associate = (db) => {


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















    db.healthcare_providers.hasMany(db.medications, {
      as: 'medications_prescribing_provider',
      foreignKey: {
          name: 'prescribing_providerId',
      },
      constraints: false,
    });


































    db.healthcare_providers.hasMany(db.medical_appointments, {
      as: 'medical_appointments_provider',
      foreignKey: {
          name: 'providerId',
      },
      constraints: false,
    });


    db.healthcare_providers.hasMany(db.lab_documents, {
      as: 'lab_documents_ordered_by_provider',
      foreignKey: {
          name: 'ordered_by_providerId',
      },
      constraints: false,
    });


    db.healthcare_providers.hasMany(db.vaccinations, {
      as: 'vaccinations_provider',
      foreignKey: {
          name: 'providerId',
      },
      constraints: false,
    });










































    db.healthcare_providers.hasMany(db.sti_tests, {
      as: 'sti_tests_clinic_provider',
      foreignKey: {
          name: 'clinic_providerId',
      },
      constraints: false,
    });











    db.healthcare_providers.hasMany(db.vision_prescriptions, {
      as: 'vision_prescriptions_optometrist',
      foreignKey: {
          name: 'optometristId',
      },
      constraints: false,
    });



    db.healthcare_providers.hasMany(db.hearing_test_logs, {
      as: 'hearing_test_logs_provider',
      foreignKey: {
          name: 'providerId',
      },
      constraints: false,
    });












//end loop



    db.healthcare_providers.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return healthcare_providers;
};


