import { api, PaginatedResult } from "@/lib/api"; export interface TimeSlotApi { id: string; date: string; start_time: string; end_time: string; is_blocked: boolean; is_booked: boolean; } export interface BookingApi { id: string; user_id: string | null; slot_id: string; slot_date: string; slot_start: string; slot_end: string; service_note: string | null; client_name: string | null; client_email: string | null; client_phone: string | null; status: "pending" | "confirmed" | "cancelled" | "completed" | "no_show"; amount_paid: number | null; stripe_payment_intent_id: string | null; admin_notes: string | null; created_at: string; } export interface CreateBookingPayload { slot_id: string; service_note?: string; guest_name?: string; guest_email?: string; guest_phone?: string; } export interface BookingResult { booking_id: string; } export async function getAvailableSlots( from_date: string, to_date: string ): Promise { return api.get( `/bookings/slots?from_date=${from_date}&to_date=${to_date}` ); } export async function createBooking(payload: CreateBookingPayload): Promise { return api.post("/bookings", payload); } export async function listMyBookings(): Promise> { return api.get>("/bookings"); } export async function cancelBooking(id: string): Promise { await api.del(`/bookings/${id}`); } // ── Admin — Schedule ────────────────────────────────────────────────────────── export interface WeeklySchedule { id: string; day_of_week: number; // 0=Monday, 6=Sunday start_time: string; end_time: string; slot_duration_minutes: number; is_active: boolean; } export interface BlockedDate { id: string; date: string; reason: string | null; } export async function adminGetSchedule(): Promise { return api.get("/admin/schedule"); } export async function adminCreateSchedule(payload: { day_of_week: number; start_time: string; end_time: string; slot_duration_minutes: number; }): Promise { return api.post("/admin/schedule", payload); } export async function adminDeleteSchedule(id: string): Promise { await api.del(`/admin/schedule/${id}`); } export async function adminListSlots(from_date: string, to_date: string): Promise { return api.get(`/admin/slots?from_date=${from_date}&to_date=${to_date}`); } export async function adminGenerateSlots(from_date: string, to_date: string): Promise<{ created: number }> { return api.post<{ created: number }>("/admin/slots/generate", { from_date, to_date }); } export async function adminUpdateSlot(id: string, is_blocked: boolean, block_reason?: string): Promise { return api.patch(`/admin/slots/${id}`, { is_blocked, block_reason }); } export async function adminDeleteSlot(id: string): Promise { await api.del(`/admin/slots/${id}`); } export async function adminGetBlockedDates(): Promise { return api.get("/admin/blocked-dates"); } export async function adminAddBlockedDate(date: string, reason?: string): Promise { return api.post("/admin/blocked-dates", { date, reason }); } export async function adminRemoveBlockedDate(id: string): Promise { await api.del(`/admin/blocked-dates/${id}`); } // ── Admin — Bookings ────────────────────────────────────────────────────────── export async function adminListBookings( status?: string ): Promise> { const qs = status ? `?status=${status}&per_page=100` : "?per_page=100"; return api.get>(`/admin/bookings${qs}`); } export async function adminUpdateBookingStatus( id: string, status: string ): Promise { return api.patch(`/admin/bookings/${id}`, { status }); } export async function adminDeleteBooking(id: string): Promise { await api.del(`/admin/bookings/${id}`); }