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

full_name: {
        type: DataTypes.TEXT,
      
      

      },

hospital_code: {
        type: DataTypes.TEXT,
      
      

      },

doctor_registration_no: {
        type: DataTypes.TEXT,
      
      

      },

specialization: {
        type: DataTypes.TEXT,
      
      

      },

years_experience: {
        type: DataTypes.INTEGER,
      
      

      },

qualification: {
        type: DataTypes.TEXT,
      
      

      },

availability_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"online",


"offline",


"busy",


"on_call"

        ],

      },

consultation_fee: {
        type: DataTypes.DECIMAL,
      
      

      },

clinic_address: {
        type: DataTypes.TEXT,
      
      

      },

clinic_latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

clinic_longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  city_doctors.associate = (db) => {


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









    db.city_doctors.hasMany(db.medical_reports, {
      as: 'medical_reports_author_city_doctor',
      foreignKey: {
          name: 'author_city_doctorId',
      },
      constraints: false,
    });




    db.city_doctors.hasMany(db.medicine_dispatches, {
      as: 'medicine_dispatches_coordinated_by_city_doctor',
      foreignKey: {
          name: 'coordinated_by_city_doctorId',
      },
      constraints: false,
    });



    db.city_doctors.hasMany(db.medical_camps, {
      as: 'medical_camps_lead_city_doctor',
      foreignKey: {
          name: 'lead_city_doctorId',
      },
      constraints: false,
    });


    db.city_doctors.hasMany(db.appointments, {
      as: 'appointments_city_doctor',
      foreignKey: {
          name: 'city_doctorId',
      },
      constraints: false,
    });













//end loop



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




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

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



  return city_doctors;
};


