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

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

/**
 * Destinations that incoming triggers should be forwarded to. Limited to 3 entries. Set the initial destination with `triggerDestination` during creation. Replace the complete set with `PATCH /v1/connect/connectors/{connector}/trigger-destinations`.
 */
export type ConnectTriggerDestination = {
  /**
   * Vercel project that receives matching trigger requests.
   */
  projectId: string;
  /**
   * Stable custom-environment ID to route this destination to. Mutually exclusive with `branch`; omitted destinations keep the legacy production behavior.
   */
  customEnvironmentId?: string | undefined;
  /**
   * Git branch used to select a preview deployment.
   */
  branch?: string | undefined;
  /**
   * Route path that receives the forwarded trigger request.
   */
  path?: string | undefined;
};

/** @internal */
export const ConnectTriggerDestination$inboundSchema: z.ZodType<
  ConnectTriggerDestination,
  z.ZodTypeDef,
  unknown
> = z.object({
  projectId: types.string(),
  customEnvironmentId: types.optional(types.string()),
  branch: types.optional(types.string()),
  path: types.optional(types.string()),
});

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