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

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 {
  LogicalExpression,
  LogicalExpression$inboundSchema,
  LogicalExpression$Outbound,
  LogicalExpression$outboundSchema,
} from "./logicalexpression.js";
import {
  ToolProperties,
  ToolProperties$inboundSchema,
  ToolProperties$Outbound,
  ToolProperties$outboundSchema,
} from "./toolproperties.js";

export type RequiresConfirmation =
  | LogicalExpression
  | ToolProperties
  | Array<string>;

export type SkipConfirmation =
  | LogicalExpression
  | ToolProperties
  | Array<string>;

export type ToolExecutionConfiguration = {
  requiresConfirmation?:
    | LogicalExpression
    | ToolProperties
    | Array<string>
    | null
    | undefined;
  skipConfirmation?:
    | LogicalExpression
    | ToolProperties
    | Array<string>
    | null
    | undefined;
  include?: Array<string> | null | undefined;
  exclude?: Array<string> | null | undefined;
};

/** @internal */
export const RequiresConfirmation$inboundSchema: z.ZodType<
  RequiresConfirmation,
  unknown
> = smartUnion([
  LogicalExpression$inboundSchema,
  ToolProperties$inboundSchema,
  z.array(z.string()),
]);
/** @internal */
export type RequiresConfirmation$Outbound =
  | LogicalExpression$Outbound
  | ToolProperties$Outbound
  | Array<string>;

/** @internal */
export const RequiresConfirmation$outboundSchema: z.ZodType<
  RequiresConfirmation$Outbound,
  RequiresConfirmation
> = smartUnion([
  LogicalExpression$outboundSchema,
  ToolProperties$outboundSchema,
  z.array(z.string()),
]);

export function requiresConfirmationToJSON(
  requiresConfirmation: RequiresConfirmation,
): string {
  return JSON.stringify(
    RequiresConfirmation$outboundSchema.parse(requiresConfirmation),
  );
}
export function requiresConfirmationFromJSON(
  jsonString: string,
): SafeParseResult<RequiresConfirmation, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => RequiresConfirmation$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'RequiresConfirmation' from JSON`,
  );
}

/** @internal */
export const SkipConfirmation$inboundSchema: z.ZodType<
  SkipConfirmation,
  unknown
> = smartUnion([
  LogicalExpression$inboundSchema,
  ToolProperties$inboundSchema,
  z.array(z.string()),
]);
/** @internal */
export type SkipConfirmation$Outbound =
  | LogicalExpression$Outbound
  | ToolProperties$Outbound
  | Array<string>;

/** @internal */
export const SkipConfirmation$outboundSchema: z.ZodType<
  SkipConfirmation$Outbound,
  SkipConfirmation
> = smartUnion([
  LogicalExpression$outboundSchema,
  ToolProperties$outboundSchema,
  z.array(z.string()),
]);

export function skipConfirmationToJSON(
  skipConfirmation: SkipConfirmation,
): string {
  return JSON.stringify(
    SkipConfirmation$outboundSchema.parse(skipConfirmation),
  );
}
export function skipConfirmationFromJSON(
  jsonString: string,
): SafeParseResult<SkipConfirmation, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => SkipConfirmation$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'SkipConfirmation' from JSON`,
  );
}

/** @internal */
export const ToolExecutionConfiguration$inboundSchema: z.ZodType<
  ToolExecutionConfiguration,
  unknown
> = z.object({
  requires_confirmation: z.nullable(
    smartUnion([
      LogicalExpression$inboundSchema,
      ToolProperties$inboundSchema,
      z.array(z.string()),
    ]),
  ).optional(),
  skip_confirmation: z.nullable(
    smartUnion([
      LogicalExpression$inboundSchema,
      ToolProperties$inboundSchema,
      z.array(z.string()),
    ]),
  ).optional(),
  include: z.nullable(z.array(z.string())).optional(),
  exclude: z.nullable(z.array(z.string())).optional(),
}).transform((v) => {
  return remap$(v, {
    "requires_confirmation": "requiresConfirmation",
    "skip_confirmation": "skipConfirmation",
  });
});
/** @internal */
export type ToolExecutionConfiguration$Outbound = {
  requires_confirmation?:
    | LogicalExpression$Outbound
    | ToolProperties$Outbound
    | Array<string>
    | null
    | undefined;
  skip_confirmation?:
    | LogicalExpression$Outbound
    | ToolProperties$Outbound
    | Array<string>
    | null
    | undefined;
  include?: Array<string> | null | undefined;
  exclude?: Array<string> | null | undefined;
};

/** @internal */
export const ToolExecutionConfiguration$outboundSchema: z.ZodType<
  ToolExecutionConfiguration$Outbound,
  ToolExecutionConfiguration
> = z.object({
  requiresConfirmation: z.nullable(
    smartUnion([
      LogicalExpression$outboundSchema,
      ToolProperties$outboundSchema,
      z.array(z.string()),
    ]),
  ).optional(),
  skipConfirmation: z.nullable(
    smartUnion([
      LogicalExpression$outboundSchema,
      ToolProperties$outboundSchema,
      z.array(z.string()),
    ]),
  ).optional(),
  include: z.nullable(z.array(z.string())).optional(),
  exclude: z.nullable(z.array(z.string())).optional(),
}).transform((v) => {
  return remap$(v, {
    requiresConfirmation: "requires_confirmation",
    skipConfirmation: "skip_confirmation",
  });
});

export function toolExecutionConfigurationToJSON(
  toolExecutionConfiguration: ToolExecutionConfiguration,
): string {
  return JSON.stringify(
    ToolExecutionConfiguration$outboundSchema.parse(toolExecutionConfiguration),
  );
}
export function toolExecutionConfigurationFromJSON(
  jsonString: string,
): SafeParseResult<ToolExecutionConfiguration, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolExecutionConfiguration$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolExecutionConfiguration' from JSON`,
  );
}
