import { createCoreAPIClient } from "@/lib/features/coreClient";
import type { AdminActivityLog } from "@/lib/features/activity-logs/query";
import type { CoreResponse } from "@/lib/features/types";
import type { HotDeal } from "./types";

const coreClient = createCoreAPIClient();

export async function listHotDeals(
  headers?: HeadersInit,
): Promise<CoreResponse<HotDeal[]>> {
  return await coreClient<HotDeal[]>("/v1/admin-console/hot-deals", {
    method: "GET",
    headers,
  });
}

export async function getHotDeal(
  id: string,
  headers?: HeadersInit,
): Promise<CoreResponse<HotDeal>> {
  return await coreClient<HotDeal>(`/v1/admin-console/hot-deals/${id}`, {
    method: "GET",
    headers,
  });
}

export async function getHotDealLogs(
  dealId: string,
  page = 1,
  pageSize = 20,
): Promise<CoreResponse<{ items: AdminActivityLog[]; totalCount: number }>> {
  const params = new URLSearchParams({
    search: `hot-deals/${dealId}`,
    limit: String(pageSize),
    offset: String((page - 1) * pageSize),
  });
  for (const m of ["POST", "PUT", "PATCH", "DELETE"]) {
    params.append("method", m);
  }
  return await coreClient(`/v2/admin/activity-logs?${params.toString()}`, {
    method: "GET",
  });
}
