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

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 { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  AuthenticationConfiguration,
  AuthenticationConfiguration$inboundSchema,
} from "./authenticationconfiguration.js";
import {
  ConnectionPreference,
  ConnectionPreference$inboundSchema,
} from "./connectionpreference.js";
import {
  ConnectorLocale,
  ConnectorLocale$inboundSchema,
} from "./connectorlocale.js";
import {
  ConnectorProtocol,
  ConnectorProtocol$inboundSchema,
} from "./connectorprotocol.js";
import { ConnectorTool, ConnectorTool$inboundSchema } from "./connectortool.js";
import { MCPServerCard, MCPServerCard$inboundSchema } from "./mcpservercard.js";
import {
  PublicAuthenticationMethod,
  PublicAuthenticationMethod$inboundSchema,
} from "./publicauthenticationmethod.js";
import {
  PublicConnectionConfig,
  PublicConnectionConfig$inboundSchema,
} from "./publicconnectionconfig.js";
import { ResourceType, ResourceType$inboundSchema } from "./resourcetype.js";
import {
  ResourceVisibility,
  ResourceVisibility$inboundSchema,
} from "./resourcevisibility.js";

export type Connector = {
  id: string;
  name: string;
  title?: string | null | undefined;
  description: string;
  createdAt: Date;
  modifiedAt: Date;
  server?: string | null | undefined;
  protocol?: ConnectorProtocol | undefined;
  iconUrl?: string | null | undefined;
  serverCard?: MCPServerCard | null | undefined;
  ownerId?: string | null | undefined;
  ownerType: ResourceType;
  visibility: ResourceVisibility;
  locale?: ConnectorLocale | null | undefined;
  systemPrompt?: string | null | undefined;
  supportedAuthMethods?: Array<PublicAuthenticationMethod> | null | undefined;
  connectionPreferences?: Array<ConnectionPreference> | null | undefined;
  connectionCredentials?: Array<AuthenticationConfiguration> | null | undefined;
  active?: boolean | null | undefined;
  privateToolExecution: boolean;
  mistral: boolean;
  isAuthenticated?: boolean | null | undefined;
  tools?: Array<ConnectorTool> | null | undefined;
  systemPromptRoute?: string | null | undefined;
  connectionConfig?: PublicConnectionConfig | null | undefined;
};

/** @internal */
export const Connector$inboundSchema: z.ZodType<Connector, unknown> = z.object({
  id: z.string(),
  name: z.string(),
  title: z.nullable(z.string()).optional(),
  description: z.string(),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  modified_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  server: z.nullable(z.string()).optional(),
  protocol: ConnectorProtocol$inboundSchema.optional(),
  icon_url: z.nullable(z.string()).optional(),
  server_card: z.nullable(MCPServerCard$inboundSchema).optional(),
  owner_id: z.nullable(z.string()).optional(),
  owner_type: ResourceType$inboundSchema,
  visibility: ResourceVisibility$inboundSchema,
  locale: z.nullable(ConnectorLocale$inboundSchema).optional(),
  system_prompt: z.nullable(z.string()).optional(),
  supported_auth_methods: z.nullable(
    z.array(PublicAuthenticationMethod$inboundSchema),
  ).optional(),
  connection_preferences: z.nullable(
    z.array(ConnectionPreference$inboundSchema),
  ).optional(),
  connection_credentials: z.nullable(
    z.array(AuthenticationConfiguration$inboundSchema),
  ).optional(),
  active: z.nullable(z.boolean()).optional(),
  private_tool_execution: z.boolean(),
  mistral: z.boolean().default(false),
  is_authenticated: z.nullable(z.boolean()).optional(),
  tools: z.nullable(z.array(ConnectorTool$inboundSchema)).optional(),
  system_prompt_route: z.nullable(z.string()).optional(),
  connection_config: z.nullable(PublicConnectionConfig$inboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "modified_at": "modifiedAt",
    "icon_url": "iconUrl",
    "server_card": "serverCard",
    "owner_id": "ownerId",
    "owner_type": "ownerType",
    "system_prompt": "systemPrompt",
    "supported_auth_methods": "supportedAuthMethods",
    "connection_preferences": "connectionPreferences",
    "connection_credentials": "connectionCredentials",
    "private_tool_execution": "privateToolExecution",
    "is_authenticated": "isAuthenticated",
    "system_prompt_route": "systemPromptRoute",
    "connection_config": "connectionConfig",
  });
});

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