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

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 {
  ConnectorToolLocale,
  ConnectorToolLocale$inboundSchema,
} from "./connectortoollocale.js";
import {
  ExecutionConfig,
  ExecutionConfig$inboundSchema,
} from "./executionconfig.js";
import {
  ResourceVisibility,
  ResourceVisibility$inboundSchema,
} from "./resourcevisibility.js";

export type ConnectorTool = {
  id: string;
  name: string;
  description: string;
  systemPrompt?: string | null | undefined;
  locale?: ConnectorToolLocale | null | undefined;
  jsonschema?: { [k: string]: any } | null | undefined;
  executionConfig: ExecutionConfig | null;
  visibility: ResourceVisibility;
  createdAt: Date;
  modifiedAt: Date;
  active?: boolean | null | undefined;
};

/** @internal */
export const ConnectorTool$inboundSchema: z.ZodType<ConnectorTool, unknown> = z
  .object({
    id: z.string(),
    name: z.string(),
    description: z.string(),
    system_prompt: z.nullable(z.string()).optional(),
    locale: z.nullable(ConnectorToolLocale$inboundSchema).optional(),
    jsonschema: z.nullable(z.record(z.string(), z.any())).optional(),
    execution_config: z.nullable(ExecutionConfig$inboundSchema),
    visibility: ResourceVisibility$inboundSchema,
    created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
    modified_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
    active: z.nullable(z.boolean()).optional(),
  }).transform((v) => {
    return remap$(v, {
      "system_prompt": "systemPrompt",
      "execution_config": "executionConfig",
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
    });
  });

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