import type {
  AdminBooking,
  CreateAdminBookingInput,
  CreatePublicBookingInput,
  PublicAvailabilityResponse,
  PublicBooking,
  PublicBookingConfirmation,
  UpdateAdminBookingStatusInput,
} from '@repo/api-contract';
import { http } from '../http';

export async function getAvailability(
  complexSlug: string,
  params: { date: string; sportId?: string }
) {
  const response = await http.get<PublicAvailabilityResponse>(
    `/api/public-bookings/complex/${complexSlug}/availability`,
    { params }
  );
  return response.data;
}

export async function createPublic(complexSlug: string, payload: CreatePublicBookingInput) {
  const response = await http.post<PublicBooking>(
    `/api/public-bookings/complex/${complexSlug}`,
    payload
  );
  return response.data;
}

export async function getConfirmation(complexSlug: string, bookingCode: string) {
  const response = await http.get<PublicBookingConfirmation>(
    `/api/public-bookings/complex/${complexSlug}/confirmation/${bookingCode}`
  );
  return response.data;
}

export async function listByComplex(complexId: string, params: { fromDate: string }) {
  const response = await http.get<{ bookings: AdminBooking[] }>(
    `/api/admin-bookings/complex/${complexId}`,
    { params }
  );
  return response.data;
}

export async function createAdmin(complexId: string, payload: CreateAdminBookingInput) {
  const response = await http.post<AdminBooking>(
    `/api/admin-bookings/complex/${complexId}`,
    payload
  );
  return response.data;
}

export async function updateStatus(bookingId: string, payload: UpdateAdminBookingStatusInput) {
  const response = await http.patch<AdminBooking>(
    `/api/admin-bookings/${bookingId}/status`,
    payload
  );
  return response.data;
}
