import { adminRequest } from "@/lib/admin-http";

const A = `/admin`;

export type AdminSettingItem = {
  key: string;
  value: unknown;
  group: string;
  description: string | null;
};

export type AdminSettingListResponse = {
  items: AdminSettingItem[];
};

export async function getAdminSettings(
  group: string,
): Promise<AdminSettingListResponse> {
  return adminRequest.get<AdminSettingListResponse>(`${A}/settings`, {
    params: { group },
  });
}

export async function updateAdminSetting(
  key: string,
  value: unknown,
): Promise<AdminSettingItem> {
  return adminRequest.put<AdminSettingItem>(`${A}/settings/${key}`, { value });
}

export type AdminSettingBatchItem = {
  key: string;
  value: unknown;
};

export async function updateAdminSettingsBatch(
  items: AdminSettingBatchItem[],
): Promise<AdminSettingListResponse> {
  return adminRequest.put<AdminSettingListResponse>(`${A}/settings/batch`, { items });
}
