/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: b9ee0c990dd6
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ClientCapabilities,
  ClientCapabilities$inboundSchema,
} from "./clientcapabilities.js";
import { MCPPrompt, MCPPrompt$inboundSchema } from "./mcpprompt.js";
import { MCPResource, MCPResource$inboundSchema } from "./mcpresource.js";
import {
  MCPServerCardMeta,
  MCPServerCardMeta$inboundSchema,
} from "./mcpservercardmeta.js";
import { MCPServerIcon, MCPServerIcon$inboundSchema } from "./mcpservericon.js";
import {
  MCPServerRemote,
  MCPServerRemote$inboundSchema,
} from "./mcpserverremote.js";
import {
  MCPServerRepository,
  MCPServerRepository$inboundSchema,
} from "./mcpserverrepository.js";
import { MCPToolMeta, MCPToolMeta$inboundSchema } from "./mcptoolmeta.js";
import {
  ServerCapabilities,
  ServerCapabilities$inboundSchema,
} from "./servercapabilities.js";

export type Resources = string | Array<MCPResource>;

export type Tools = string | Array<MCPToolMeta>;

export type Prompts = string | Array<MCPPrompt>;

export type MCPServerCard = {
  /**
   * URL to the JSON schema definition
   */
  dollarSchema?: string | null | undefined;
  /**
   * Server identifier in reverse-DNS format with exactly one /
   */
  name: string;
  /**
   * Server version (semantic versioning preferred)
   */
  version: string;
  /**
   * Capabilities that a server may support.
   */
  capabilities?: ServerCapabilities | undefined;
  title?: string | null | undefined;
  description?: string | null | undefined;
  websiteUrl?: string | null | undefined;
  repository?: MCPServerRepository | null | undefined;
  icons?: Array<MCPServerIcon> | null | undefined;
  remotes?: Array<MCPServerRemote> | null | undefined;
  requires?: ClientCapabilities | null | undefined;
  resources?: string | Array<MCPResource> | null | undefined;
  tools?: string | Array<MCPToolMeta> | null | undefined;
  prompts?: string | Array<MCPPrompt> | null | undefined;
  meta?: MCPServerCardMeta | null | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const Resources$inboundSchema: z.ZodType<Resources, unknown> =
  smartUnion([z.string(), z.array(MCPResource$inboundSchema)]);

export function resourcesFromJSON(
  jsonString: string,
): SafeParseResult<Resources, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Resources$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Resources' from JSON`,
  );
}

/** @internal */
export const Tools$inboundSchema: z.ZodType<Tools, unknown> = smartUnion([
  z.string(),
  z.array(MCPToolMeta$inboundSchema),
]);

export function toolsFromJSON(
  jsonString: string,
): SafeParseResult<Tools, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Tools$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Tools' from JSON`,
  );
}

/** @internal */
export const Prompts$inboundSchema: z.ZodType<Prompts, unknown> = smartUnion([
  z.string(),
  z.array(MCPPrompt$inboundSchema),
]);

export function promptsFromJSON(
  jsonString: string,
): SafeParseResult<Prompts, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Prompts$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Prompts' from JSON`,
  );
}

/** @internal */
export const MCPServerCard$inboundSchema: z.ZodType<MCPServerCard, unknown> = z
  .object({
    $schema: z.nullable(z.string()).optional(),
    name: z.string(),
    version: z.string(),
    capabilities: ServerCapabilities$inboundSchema.optional(),
    title: z.nullable(z.string()).optional(),
    description: z.nullable(z.string()).optional(),
    websiteUrl: z.nullable(z.string()).optional(),
    repository: z.nullable(MCPServerRepository$inboundSchema).optional(),
    icons: z.nullable(z.array(MCPServerIcon$inboundSchema)).optional(),
    remotes: z.nullable(z.array(MCPServerRemote$inboundSchema)).optional(),
    requires: z.nullable(ClientCapabilities$inboundSchema).optional(),
    resources: z.nullable(
      smartUnion([z.string(), z.array(MCPResource$inboundSchema)]),
    ).optional(),
    tools: z.nullable(
      smartUnion([z.string(), z.array(MCPToolMeta$inboundSchema)]),
    ).optional(),
    prompts: z.nullable(
      smartUnion([z.string(), z.array(MCPPrompt$inboundSchema)]),
    ).optional(),
    _meta: z.nullable(MCPServerCardMeta$inboundSchema).optional(),
  }).catchall(z.any()).transform((v) => {
    return remap$(v, {
      "$schema": "dollarSchema",
      "_meta": "meta",
    });
  });

export function mcpServerCardFromJSON(
  jsonString: string,
): SafeParseResult<MCPServerCard, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MCPServerCard$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MCPServerCard' from JSON`,
  );
}
