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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const UrlPostKind = {
  Exact: "exact",
  Canonical: "canonical",
  Substring: "substring",
  Regex: "regex",
} as const;
export type UrlPostKind = ClosedEnum<typeof UrlPostKind>;

export type UrlPost = {
  kind?: UrlPostKind | undefined;
  url?: string | undefined;
  substring?: string | undefined;
  pattern?: string | undefined;
};

/** @internal */
export const UrlPostKind$inboundSchema: z.ZodNativeEnum<typeof UrlPostKind> = z
  .nativeEnum(UrlPostKind);
/** @internal */
export const UrlPostKind$outboundSchema: z.ZodNativeEnum<typeof UrlPostKind> =
  UrlPostKind$inboundSchema;

/** @internal */
export const UrlPost$inboundSchema: z.ZodType<UrlPost, z.ZodTypeDef, unknown> =
  z.object({
    kind: UrlPostKind$inboundSchema.optional(),
    url: z.string().optional(),
    substring: z.string().optional(),
    pattern: z.string().optional(),
  });
/** @internal */
export type UrlPost$Outbound = {
  kind?: string | undefined;
  url?: string | undefined;
  substring?: string | undefined;
  pattern?: string | undefined;
};

/** @internal */
export const UrlPost$outboundSchema: z.ZodType<
  UrlPost$Outbound,
  z.ZodTypeDef,
  UrlPost
> = z.object({
  kind: UrlPostKind$outboundSchema.optional(),
  url: z.string().optional(),
  substring: z.string().optional(),
  pattern: z.string().optional(),
});

export function urlPostToJSON(urlPost: UrlPost): string {
  return JSON.stringify(UrlPost$outboundSchema.parse(urlPost));
}
export function urlPostFromJSON(
  jsonString: string,
): SafeParseResult<UrlPost, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => UrlPost$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'UrlPost' from JSON`,
  );
}
