import { apiClient } from "@shared/api/client";

export interface ContentPage {
  id: string;
  slug: string;
  title: string;
  body: string;
  status: string;
}

export async function getPageBySlug(slug: string) {
  const { data } = await apiClient.get(`/api/v1/content/pages/${slug}`);
  return data;
}

export async function getAdminPages(): Promise<ContentPage[]> {
  const { data } = await apiClient.get<{ data: ContentPage[] }>("/api/v1/content/pages/manage/all");
  return data.data;
}

export async function createContentPage(payload: {
  slug: string;
  title: string;
  body: string;
  status: string;
}): Promise<ContentPage> {
  const { data } = await apiClient.post<ContentPage>("/api/v1/content/pages", payload);
  return data;
}

export async function updateContentPage(
  pageId: string,
  payload: { title?: string; body?: string; status?: string }
): Promise<ContentPage> {
  const { data } = await apiClient.patch<ContentPage>(`/api/v1/content/pages/${pageId}`, payload);
  return data;
}

export async function deleteContentPage(pageId: string): Promise<void> {
  await apiClient.delete(`/api/v1/content/pages/${pageId}`);
}
