import { apiRequest } from './http';
import { platformOperations } from './platform-operations.generated';
import type { HttpMethod, OperationInput, PlatformOperation } from './types';

export function platformOperation(method: HttpMethod, path: string): PlatformOperation {
  const operation = platformOperations.find((item) => item.method === method && item.path === path);
  if (!operation) throw new Error(`平台接口契约缺失：${method} ${path}`);
  return operation;
}

export function platformRequest<T>(method: HttpMethod, path: string, input: OperationInput = {}, signal?: AbortSignal) {
  return apiRequest<T>(platformOperation(method, path), input, signal);
}
