import { get } from "./shared";

export interface JellyseerStat {
	key: string;
	label: string;
	value: number;
}

export interface JellyseerRecentRequest {
	id?: number | string;
	type?: number | string;
	name?: string;
	status?: string;
	media_status?: string;
	created_at?: number | string;
}

export interface JellyseerStatsResponse {
	stats: JellyseerStat[];
	recent: JellyseerRecentRequest[];
	detail?: string | null;
}

/** Fetch Jellyseerr request stats for a Jellyfin service instance. */
export async function fetchJellyseerrStats(
	jellyfinServiceId?: string,
): Promise<JellyseerStatsResponse> {
	return get<JellyseerStatsResponse>(
		"/api/jellyseerr/stats",
		jellyfinServiceId ? { jellyfin_service_id: jellyfinServiceId } : undefined,
	);
}

export interface JellyseerRequest {
	id?: number | string;
	type?: string;
	name?: string;
	status?: string;
	media_status?: string;
	created_at?: number | string;
}

/** Fetch Jellyseerr requests (all, mapped) for the Requests tab table. */
export async function fetchJellyseerrRequests(
	jellyfinServiceId?: string,
): Promise<JellyseerRequest[]> {
	const res = await get<{ requests: JellyseerRequest[]}>(
		"/api/jellyseerr/requests",
		jellyfinServiceId ? { jellyfin_service_id: jellyfinServiceId } : undefined,
	);
	return res.requests ?? [];
}
