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

doctor_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"city",


"rural"

        ],

      },

medical_license_number: {
        type: DataTypes.TEXT,
      
      

      },

specialization: {
        type: DataTypes.TEXT,
      
      

      },

qualification: {
        type: DataTypes.TEXT,
      
      

      },

years_of_experience: {
        type: DataTypes.INTEGER,
      
      

      },

availability_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"available",


"busy",


"offline"

        ],

      },

consultation_fee_note: {
        type: DataTypes.TEXT,
      
      

      },

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

  doctor_profiles.associate = (db) => {


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







    db.doctor_profiles.hasMany(db.patient_profiles, {
      as: 'patient_profiles_primary_rural_doctor',
      foreignKey: {
          name: 'primary_rural_doctorId',
      },
      constraints: false,
    });


    db.doctor_profiles.hasMany(db.medical_camps, {
      as: 'medical_camps_camp_lead_doctor',
      foreignKey: {
          name: 'camp_lead_doctorId',
      },
      constraints: false,
    });


    db.doctor_profiles.hasMany(db.appointments, {
      as: 'appointments_doctor',
      foreignKey: {
          name: 'doctorId',
      },
      constraints: false,
    });


    db.doctor_profiles.hasMany(db.consultations, {
      as: 'consultations_primary_doctor',
      foreignKey: {
          name: 'primary_doctorId',
      },
      constraints: false,
    });

    db.doctor_profiles.hasMany(db.consultations, {
      as: 'consultations_secondary_doctor',
      foreignKey: {
          name: 'secondary_doctorId',
      },
      constraints: false,
    });


    db.doctor_profiles.hasMany(db.medical_reports, {
      as: 'medical_reports_author_doctor',
      foreignKey: {
          name: 'author_doctorId',
      },
      constraints: false,
    });




    db.doctor_profiles.hasMany(db.prescriptions, {
      as: 'prescriptions_prescribed_by_doctor',
      foreignKey: {
          name: 'prescribed_by_doctorId',
      },
      constraints: false,
    });



    db.doctor_profiles.hasMany(db.medicine_dispatches, {
      as: 'medicine_dispatches_dispatched_by_doctor',
      foreignKey: {
          name: 'dispatched_by_doctorId',
      },
      constraints: false,
    });





    db.doctor_profiles.hasMany(db.chat_sessions, {
      as: 'chat_sessions_doctor',
      foreignKey: {
          name: 'doctorId',
      },
      constraints: false,
    });

    db.doctor_profiles.hasMany(db.chat_sessions, {
      as: 'chat_sessions_second_doctor',
      foreignKey: {
          name: 'second_doctorId',
      },
      constraints: false,
    });





    db.doctor_profiles.hasMany(db.feedbacks, {
      as: 'feedbacks_doctor',
      foreignKey: {
          name: 'doctorId',
      },
      constraints: false,
    });



//end loop



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

    db.doctor_profiles.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return doctor_profiles;
};


