import { inject, Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { API_BASE_URL } from './api-config.token'; export type ShowListItem = { id: number; title: string; slug: string; summary: string; poster_image: string; }; export type VenueSummary = { name: string; city: string; }; export type ShowPerformance = { id: number; starts_at: string; venue: VenueSummary; booking_enabled: boolean; available_seats: number; }; export type ShowDetail = ShowListItem & { description: string; performances?: ShowPerformance[]; }; export type ReservationCreatePayload = { name: string; email: string; party_size: number; }; export type ReservationCreateResponse = { id: number; status: string; performance: number; party_size: number; message: string; }; export type ReservationConfirmResponse = { reservation_id: number; status: string; party_size: number; qr_code_url?: string; qr_code_image?: string; }; export type CheckInPreviewResponse = { status: 'valid'; reservation_id: number; performance_id: number; show_title: string; venue_name: string; starts_at: string; party_size: number; }; export type CheckInConfirmResponse = { status: 'checked_in'; reservation_id: number; performance_id: number; party_size: number; checked_in_at: string; checked_in_by: number; }; type ShowListResponse = { results: ShowListItem[]; }; type PerformanceListResponse = { results: ShowPerformance[]; }; @Injectable({ providedIn: 'root', }) export class ShowsApiService { private readonly http = inject(HttpClient); private readonly apiBaseUrl = inject(API_BASE_URL); listShows(): Observable { return this.http.get(`${this.apiBaseUrl}/shows/`); } getShow(slug: string): Observable { return this.http.get(`${this.apiBaseUrl}/shows/${slug}/`); } listPerformancesForShow(slug: string): Observable { return this.http.get(`${this.apiBaseUrl}/performances/`, { params: { show: slug }, }); } createReservation(performanceId: string, payload: ReservationCreatePayload): Observable { return this.http.post( `${this.apiBaseUrl}/performances/${performanceId}/reservations/`, payload, ); } confirmReservation(token: string): Observable { return this.http.get(`${this.apiBaseUrl}/reservations/confirm/`, { params: { token }, }); } previewCheckIn(token: string): Observable { return this.http.post(`${this.apiBaseUrl}/check-ins/preview/`, { token }); } confirmCheckIn(token: string): Observable { return this.http.post(`${this.apiBaseUrl}/check-ins/confirm/`, { token }); } }