/**
 * Generated by scripts/generate_public_operations.py from openapi.yaml. Do not edit manually.
 */

/** A single public (unauthenticated) OpenAPI operation. */
export interface PublicOperation {
  method: string;
  pathPattern: RegExp;
}

/** Operations that may be called without CDP API credentials, per openapi.yaml. */
export const PUBLIC_OPERATIONS: PublicOperation[] = [
  { method: "GET", pathPattern: new RegExp("/v2/coinbase\\-accounts/balances$") },
  { method: "POST", pathPattern: new RegExp("/v2/mandates/[^/]+/approvals/wallet$") },
  { method: "GET", pathPattern: new RegExp("/v2/mandates/[^/]+/approvals/wallet/options$") },
  { method: "POST", pathPattern: new RegExp("/v2/mandates/[^/]+/revocations/wallet$") },
  { method: "GET", pathPattern: new RegExp("/v2/mandates/[^/]+/revocations/wallet/options$") },
  {
    method: "POST",
    pathPattern: new RegExp("/v2/payment\\-sessions/[^/]+/authorizations/coinbase$"),
  },
  {
    method: "POST",
    pathPattern: new RegExp("/v2/payment\\-sessions/[^/]+/authorizations/wallet$"),
  },
  {
    method: "GET",
    pathPattern: new RegExp("/v2/payment\\-sessions/[^/]+/authorizations/wallet/options$"),
  },
  { method: "POST", pathPattern: new RegExp("/v2/payment\\-sessions/[^/]+/authorizations/x402$") },
  { method: "GET", pathPattern: new RegExp("/v2/x402/discovery/bundles$") },
  { method: "GET", pathPattern: new RegExp("/v2/x402/discovery/bundles/[^/]+$") },
  { method: "POST", pathPattern: new RegExp("/v2/x402/discovery/mcp$") },
  { method: "GET", pathPattern: new RegExp("/v2/x402/discovery/merchant$") },
  { method: "GET", pathPattern: new RegExp("/v2/x402/discovery/resources$") },
  { method: "GET", pathPattern: new RegExp("/v2/x402/discovery/search$") },
  { method: "POST", pathPattern: new RegExp("/v2/x402/validate$") },
];

/**
 * Returns true if the given HTTP method and path correspond to a public (unauthenticated)
 * operation, as declared by the `security` field in openapi.yaml.
 *
 * @param method - The HTTP method of the request (e.g. "GET").
 * @param path - The URL path of the request (e.g. "/v2/x402/discovery/search").
 * @returns True if the operation does not require CDP API credentials.
 */
export function isPublicOperation(method: string, path: string): boolean {
  const normalizedMethod = method.toUpperCase();
  return PUBLIC_OPERATIONS.some(
    operation => operation.method === normalizedMethod && operation.pathPattern.test(path),
  );
}
