import type { EventAttendeeFilter, EventAttendeeResponseDto, MyEventsControllerAttendees200, OwnerEventInsightsResponseDto, } from '@/api/generated/models' import { getAdminBookings } from '@/api/generated/admin-bookings/admin-bookings' import { getAdminEvents } from '@/api/generated/admin-events/admin-events' import { getBookings } from '@/api/generated/bookings/bookings' import { getMyEvents } from '@/api/generated/my-events/my-events' import { unwrapApiPayload } from '@/helpers/listResponse' import axiosInstance from '@/config/axios' import type { CreatedEvent } from '@/services/events' import type { EventFaq, EventMedia } from '@/services/eventDetail' export type EventAttendee = Omit & { firstName: string | null lastName: string | null confirmedAt: string | null checkedInAt: string | null noShowAt: string | null } /** Extended until OpenAPI client is regenerated with traffic insights. */ export type EventManagementInsights = OwnerEventInsightsResponseDto & { traffic?: { instagram: { uniqueVisits: number; confirmedBookings: number } telegram: { uniqueVisits: number; confirmedBookings: number } } } export type AttendanceFilter = EventAttendeeFilter export interface EventManagementBootstrap { event: CreatedEvent insights: EventManagementInsights categoryName: string cityName: string provinceName: string media: EventMedia[] faqs: EventFaq[] } export interface EventAttendeePage { items: EventAttendee[] totalItemsCount: number totalPages: number } const myEventsApi = getMyEvents() const bookingsApi = getBookings() const adminEventsApi = getAdminEvents() const adminBookingsApi = getAdminBookings() export async function fetchEventManagementInsights(eventId: string): Promise { const response = await myEventsApi.myEventsControllerOwnerInsights(eventId) return unwrapApiPayload(response.data) } export async function fetchEventManagementBootstrap(eventId: string): Promise { const response = await axiosInstance.get(`events/${eventId}/management-bootstrap`) return unwrapApiPayload(response.data) } /** Admin can view insights for any organizer's event (no ownership check). */ export async function fetchEventInsightsAsAdmin(eventId: string): Promise { const response = await adminEventsApi.adminEventsControllerInsights(eventId) return unwrapApiPayload(response.data) } export async function fetchEventAttendees( eventId: string, options: { search?: string attendance?: AttendanceFilter page?: number pageSize?: number } = {} ): Promise { const response = await myEventsApi.myEventsControllerAttendees(eventId, { page: options.page ?? 1, pageSize: options.pageSize ?? 20, sort: '-createdAt', search: options.search?.trim() || undefined, attendance: options.attendance ?? 'all', }) const payload = unwrapApiPayload(response.data) return { items: Array.isArray(payload.items) ? (payload.items as EventAttendee[]) : [], totalItemsCount: Number(payload.response?.totalItemsCount ?? 0), totalPages: Number(payload.response?.totalPages ?? 0), } } export async function checkInEventAttendee(bookingId: string): Promise { await bookingsApi.bookingsControllerCheckIn(bookingId) } /** Admin can check in a guest for any organizer's event (no ownership check). */ export async function checkInBookingAsAdmin(bookingId: string): Promise { await adminBookingsApi.adminBookingsControllerCheckIn(bookingId) }