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

import * as z from "zod/v3";
import { smartUnion } from "../types/smartUnion.js";

export type CustomEnvironment = {
  /**
   * Project that receives matching trigger requests.
   */
  projectId: string;
  /**
   * Stable custom environment ID that belongs to the destination project.
   */
  customEnvironmentId: string;
  /**
   * Route path on the linked project that receives forwarded trigger requests.
   */
  path?: string | undefined;
};

export type Branch = {
  /**
   * Project that receives matching trigger requests.
   */
  projectId: string;
  /**
   * Git branch used to select a preview deployment.
   */
  branch: string;
  /**
   * Route path on the linked project that receives forwarded trigger requests.
   */
  path?: string | undefined;
};

export type DefaultDeployment = {
  /**
   * Project that receives matching trigger requests.
   */
  projectId: string;
  /**
   * Route path on the linked project that receives forwarded trigger requests.
   */
  path?: string | undefined;
};

/**
 * A destination in the complete replacement set. Each destination targets the default deployment, a branch, or a custom environment.
 */
export type ConnectTriggerDestinationInput =
  | Branch
  | CustomEnvironment
  | DefaultDeployment;

/** @internal */
export type CustomEnvironment$Outbound = {
  projectId: string;
  customEnvironmentId: string;
  path?: string | undefined;
};

/** @internal */
export const CustomEnvironment$outboundSchema: z.ZodType<
  CustomEnvironment$Outbound,
  z.ZodTypeDef,
  CustomEnvironment
> = z.object({
  projectId: z.string(),
  customEnvironmentId: z.string(),
  path: z.string().optional(),
});

export function customEnvironmentToJSON(
  customEnvironment: CustomEnvironment,
): string {
  return JSON.stringify(
    CustomEnvironment$outboundSchema.parse(customEnvironment),
  );
}

/** @internal */
export type Branch$Outbound = {
  projectId: string;
  branch: string;
  path?: string | undefined;
};

/** @internal */
export const Branch$outboundSchema: z.ZodType<
  Branch$Outbound,
  z.ZodTypeDef,
  Branch
> = z.object({
  projectId: z.string(),
  branch: z.string(),
  path: z.string().optional(),
});

export function branchToJSON(branch: Branch): string {
  return JSON.stringify(Branch$outboundSchema.parse(branch));
}

/** @internal */
export type DefaultDeployment$Outbound = {
  projectId: string;
  path?: string | undefined;
};

/** @internal */
export const DefaultDeployment$outboundSchema: z.ZodType<
  DefaultDeployment$Outbound,
  z.ZodTypeDef,
  DefaultDeployment
> = z.object({
  projectId: z.string(),
  path: z.string().optional(),
});

export function defaultDeploymentToJSON(
  defaultDeployment: DefaultDeployment,
): string {
  return JSON.stringify(
    DefaultDeployment$outboundSchema.parse(defaultDeployment),
  );
}

/** @internal */
export type ConnectTriggerDestinationInput$Outbound =
  | Branch$Outbound
  | CustomEnvironment$Outbound
  | DefaultDeployment$Outbound;

/** @internal */
export const ConnectTriggerDestinationInput$outboundSchema: z.ZodType<
  ConnectTriggerDestinationInput$Outbound,
  z.ZodTypeDef,
  ConnectTriggerDestinationInput
> = smartUnion([
  z.lazy(() => Branch$outboundSchema),
  z.lazy(() => CustomEnvironment$outboundSchema),
  z.lazy(() => DefaultDeployment$outboundSchema),
]);

export function connectTriggerDestinationInputToJSON(
  connectTriggerDestinationInput: ConnectTriggerDestinationInput,
): string {
  return JSON.stringify(
    ConnectTriggerDestinationInput$outboundSchema.parse(
      connectTriggerDestinationInput,
    ),
  );
}
