import { Injectable } from '@nestjs/common';
import { DoctorSlotShift } from './entities/doctor_slot_shift.entity';
import { DataSource } from 'typeorm';
import axios from 'axios';

@Injectable()
export class DoctorSlotShiftService {

  constructor(private readonly connection: DataSource,
  ) { }

  async getShift(Entity: DoctorSlotShift) {
    if (!Entity.hospital_id) {
      return {
        "status": "failed",
        "message": "Enter hospital_id to get shift"
      }
    }
    try {
      const [getBaseURL] = await this.connection.query(`select op_hub_base_url from hospitals where plenome_id = ?`, [Entity.hospital_id])
      const find_all_process_list = await axios.post(`${getBaseURL.op_hub_base_url}/op-hub-doctor-slot-shift-service/slot`, Entity)
      return find_all_process_list.data
    } catch (error) {
      throw new Error(error);
    }
  }

  async getSlot(Entity: DoctorSlotShift) {
    if (!Entity.hospital_id) {
      return {
        "status": "failed",
        "message": "Enter hospital_id to get shift"
      }
    }
    try {
      const [getBaseURL] = await this.connection.query(`select op_hub_base_url from hospitals where plenome_id = ?`, [Entity.hospital_id])
      const find_all_process_list = await axios.post(`${getBaseURL.op_hub_base_url}/op-hub-doctor-slot-shift-service/slot`, Entity)
      return find_all_process_list.data
    } catch (error) {
      throw new Error(error);
    }
  }

}
