'use client';

import type {
  HostDetail,
  HostStats,
  HostSummary,
  RotatePushSecretResponse,
  RotateCallbackSecretResponse,
  RotateSecretResponse,
  UpdateHostRequest,
} from '@pac/types';
import { api } from '@/lib/api-client';

const BASE = '/pac/v1/admin/host/self';

export const hostApi = {
  getSelf: () => api.get<HostDetail>(BASE),
  getStats: () => api.get<HostStats>(`${BASE}/stats`),
  update: (body: UpdateHostRequest) => api.patch<HostSummary>(BASE, body),

  rotateAppSecret: () => api.post<RotateSecretResponse>(`${BASE}/rotate-app-secret`),
  addPushSecret: () => api.post<RotatePushSecretResponse>(`${BASE}/push-secrets`),
  removePushSecret: (suffix: string) =>
    api.delete<{ totalKeysRemaining: number }>(`${BASE}/push-secrets/${encodeURIComponent(suffix)}`),

  addCallbackSecret: () => api.post<RotateCallbackSecretResponse>(`${BASE}/callback-secrets`),
  removeCallbackSecret: (suffix: string) =>
    api.delete<{ totalKeysRemaining: number }>(
      `${BASE}/callback-secrets/${encodeURIComponent(suffix)}`,
    ),
};
