import { get, post, put } from './apiClient';
import type {
  ApiKey,
  ApiKeyDetail,
  ApiKeyCreateResponse,
  CreateApiKeyRequest,
  ApiKeyRequest,
  ApiKeyRequestCreateDto,
  ApiKeyRequestReviewDto,
  Permission,
} from '../types/apikey';

// My Keys
export const getMyKeys = () => get<ApiKey[]>('/keys');
export const getAllKeys = () => get<ApiKey[]>('/keys/all');
export const getKeyDetail = (id: number) => get<ApiKeyDetail>(`/keys/${id}`);
export const createKey = (req: CreateApiKeyRequest) => post<ApiKeyCreateResponse>('/keys', req);
export const revokeKey = (id: number) => put<void>(`/keys/${id}/revoke`);

// Requests
export const createKeyRequest = (req: ApiKeyRequestCreateDto) =>
  post<ApiKeyRequest>('/keys/requests', req);
export const getMyRequests = () => get<ApiKeyRequest[]>('/keys/requests/my');
export const getAllRequests = () => get<ApiKeyRequest[]>('/keys/requests');
export const reviewRequest = (id: number, req: ApiKeyRequestReviewDto) =>
  put<ApiKeyCreateResponse | null>(`/keys/requests/${id}/review`, req);

// Permissions
export const getPermissions = (keyId: number) => get<Permission[]>(`/keys/${keyId}/permissions`);
