import { get, post, patch, del } from './client.js';

export async function fetchVisits(params = {}) {
  const query = new URLSearchParams(params).toString();
  return get(query ? `/api/patvisit?${query}` : '/api/patvisit');
}

export async function fetchVisit(id) {
  return get(`/api/patvisit/${encodeURIComponent(id)}`);
}

export async function fetchVisitsByPatient(patientId) {
  return get(`/api/patvisit/patient/${encodeURIComponent(patientId)}`);
}

export async function createVisit(data) {
  return post('/api/patvisit', data);
}

export async function updateVisit(id, data) {
  return patch(`/api/patvisit/${encodeURIComponent(id)}`, data);
}

export async function deleteVisit(id) {
  return del('/api/patvisit', { body: JSON.stringify({ InternalPVID: id }) });
}

export async function createADT(data) {
  return post('/api/patvisitadt', data);
}

export async function updateADT(id, data) {
  return patch(`/api/patvisitadt/${encodeURIComponent(id)}`, data);
}

export async function fetchVisitADTHistory(visitId) {
  return get(`/api/patvisitadt/visit/${encodeURIComponent(visitId)}`);
}
