/**
 * Serviço de Lista de Espera
 */

import { apiClient } from "../api/client";
import type {
  WaitlistEntry,
  CreateWaitlistInput,
  WaitlistFilters,
} from "./types";

class WaitlistService {
  /**
   * Lista entradas da fila de espera
   */
  async list(filters?: WaitlistFilters): Promise<WaitlistEntry[]> {
    const params: Record<string, string> = {};

    if (filters?.patient_id) {
      params.patient_id = filters.patient_id;
    }

    if (filters?.doctor_id) {
      params.doctor_id = filters.doctor_id;
    }

    if (filters?.status) {
      params.status = filters.status;
    }

    const response = await apiClient.callFunction<WaitlistEntry[]>("waitlist", {
      method: "GET",
      filters,
    });

    return response.data;
  }

  /**
   * Adiciona paciente à lista de espera
   */
  async create(data: CreateWaitlistInput): Promise<WaitlistEntry> {
    const response = await apiClient.callFunction<WaitlistEntry>(
      "waitlist",
      data
    );

    return response.data;
  }
}

export const waitlistService = new WaitlistService();
