import { request, BASE } from "./client";

// ── Types ────────────────────────────────────────────────────────────────────

export interface AdminTechniquePageItem {
  id: string;
  title: string;
  slug: string;
  creator_name: string;
  creator_slug: string;
  topic_category: string;
  body_sections_format: string;
  source_video_count: number;
  version_count: number;
  created_at: string;
  updated_at: string;
}

export interface AdminTechniquePageListResponse {
  items: AdminTechniquePageItem[];
  total: number;
  offset: number;
  limit: number;
}

// ── Functions ────────────────────────────────────────────────────────────────

export async function fetchAdminTechniquePages(
  params: {
    multi_source_only?: boolean;
    creator?: string;
    sort?: string;
    offset?: number;
    limit?: number;
  } = {},
): Promise<AdminTechniquePageListResponse> {
  const qs = new URLSearchParams();
  if (params.multi_source_only) qs.set("multi_source_only", "true");
  if (params.creator) qs.set("creator", params.creator);
  if (params.sort) qs.set("sort", params.sort);
  if (params.offset !== undefined) qs.set("offset", String(params.offset));
  if (params.limit !== undefined) qs.set("limit", String(params.limit));
  const query = qs.toString();
  return request<AdminTechniquePageListResponse>(
    `${BASE}/admin/pipeline/technique-pages${query ? `?${query}` : ""}`,
  );
}
