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

import * as z from "zod/v3";
import { ClosedEnum } from "../types/enums.js";
import { smartUnion } from "../types/smartUnion.js";
import {
  ConnectConnectorCreateData,
  ConnectConnectorCreateData$Outbound,
  ConnectConnectorCreateData$outboundSchema,
} from "./connectconnectorcreatedata.js";

export const ConnectCreateConnectorRequestEnvironments1 = {
  Development: "development",
  Preview: "preview",
  Production: "production",
} as const;
export type ConnectCreateConnectorRequestEnvironments1 = ClosedEnum<
  typeof ConnectCreateConnectorRequestEnvironments1
>;

/**
 * A built-in environment name or the stable env_* ID of a custom environment.
 */
export type ConnectCreateConnectorRequestEnvironments =
  | ConnectCreateConnectorRequestEnvironments1
  | string;

export type TriggerDestinationCustomEnvironment = {
  /**
   * Project that receives triggers. During connector creation, omit it to use the top-level projectId.
   */
  projectId?: string | undefined;
  /**
   * 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 TriggerDestinationBranch = {
  /**
   * Project that receives triggers. During connector creation, omit it to use the top-level projectId.
   */
  projectId?: string | undefined;
  /**
   * 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 TriggerDestinationDefaultDeployment = {
  /**
   * Project that receives triggers. During connector creation, omit it to use the top-level projectId.
   */
  projectId?: string | undefined;
  /**
   * Route path on the linked project that receives forwarded trigger requests.
   */
  path?: string | undefined;
};

/**
 * Initial trigger destination. Requires triggers to be enabled and a projectId here or at the top level. Connector responses expose the resulting set as triggerDestinations. Replace the complete set with PATCH /v1/connect/connectors/{connector}/trigger-destinations.
 */
export type ConnectCreateConnectorRequestTriggerDestination =
  | TriggerDestinationBranch
  | TriggerDestinationCustomEnvironment
  | TriggerDestinationDefaultDeployment;

export type PresetConfiguration = {
  /**
   * Provider configuration. With type, provide the complete configuration for that type. With service and connectionMethod, provide only credentials and preferences; Connect supplies the type, endpoints, templates, and defaults. Other connector types accept an arbitrary object.
   */
  data: ConnectConnectorCreateData;
  /**
   * SHA-1 digest of a PNG or JPEG icon that is at least 640 by 640 pixels. This field does not accept a URL or image bytes.
   *
   * @remarks
   *
   * First compute the digest and upload the raw image with [POST /v2/files](https://vercel.com/docs/rest-api/deployments/upload-deployment-files). Send `Content-Length` and the same 40-character digest in `x-vercel-digest`. Then set `icon` to that digest.
   *
   * ```js
   * import { createHash } from 'node:crypto';
   * import { readFile } from 'node:fs/promises';
   *
   * const VERCEL_TOKEN = process.env.VERCEL_TOKEN;
   * const connectorId = 'scl_...';
   * const bytes = await readFile('icon.png');
   * const digest = createHash('sha1').update(bytes).digest('hex');
   *
   * await fetch('https://api.vercel.com/v2/files', {
   *   method: 'POST',
   *   headers: {
   *     Authorization: `Bearer ${VERCEL_TOKEN}`,
   *     'Content-Type': 'application/octet-stream',
   *     'Content-Length': String(bytes.length),
   *     'x-vercel-digest': digest,
   *   },
   *   body: bytes,
   * });
   *
   * await fetch(`https://api.vercel.com/v2/connect/connectors/${connectorId}`, {
   *   method: 'PATCH',
   *   headers: {
   *     Authorization: `Bearer ${VERCEL_TOKEN}`,
   *     'Content-Type': 'application/json',
   *   },
   *   body: JSON.stringify({ icon: digest }),
   * });
   * ```
   */
  icon?: string | undefined;
  /**
   * Branding background color (6-digit hex, for example
   */
  backgroundColor?: string | undefined;
  /**
   * Branding accent color (6-digit hex, for example
   */
  accentColor?: string | undefined;
  /**
   * Connector implementation type for full configuration. Known types: api-key, discord, github, linear, linq, microsoft-entra, oauth, photon, salesforce, sendblue, slack, snowflake, snowflake-wif. Optional when service and connectionMethod select the type.
   */
  type?: string | undefined;
  /**
   * Service slug or URL for which the connector is used. Required when connectionMethod is set. Service alone does not enable preset configuration.
   */
  service: string;
  /**
   * Connection method slug of the service. Use it with service to select preset configuration.
   */
  connectionMethod: string;
  /**
   * Values for the selected connection method's template fields. Requires connectionMethod.
   */
  params?: { [k: string]: string } | undefined;
  /**
   * Which of the service's targets this connector is for. Requires \"connectionMethod\" and must be one that method serves. Optional.
   */
  target?: string | undefined;
  /**
   * Optional team-scoped unique identifier for the connector. If omitted or empty, Connect generates a value.
   */
  uid?: string | undefined;
  /**
   * Connector name. The value is trimmed and cannot contain control characters. If omitted or empty, the project name is used. A name or projectId is required. API key connectors require name.
   */
  name?: string | undefined;
  /**
   * Project to connect during creation. If environments is omitted, the connection uses development, preview, and production.
   */
  projectId?: string | undefined;
  /**
   * Environments for the project connection. Requires projectId. Use one or more built-in environment names or stable custom environment IDs that belong to the project. Duplicate values are accepted and removed.
   */
  environments?:
    | Array<ConnectCreateConnectorRequestEnvironments1 | string>
    | undefined;
  /**
   * Whether the triggers are enabled for this connector.
   */
  triggers?: boolean | undefined;
  /**
   * Initial trigger destination. Requires triggers to be enabled and a projectId here or at the top level. Connector responses expose the resulting set as triggerDestinations. Replace the complete set with PATCH /v1/connect/connectors/{connector}/trigger-destinations.
   */
  triggerDestination?:
    | TriggerDestinationBranch
    | TriggerDestinationCustomEnvironment
    | TriggerDestinationDefaultDeployment
    | undefined;
  /**
   * Default trigger events for this connector.
   */
  events?: Array<string> | undefined;
};

export const ConnectCreateConnectorRequestEnvironments11 = {
  Development: "development",
  Preview: "preview",
  Production: "production",
} as const;
export type ConnectCreateConnectorRequestEnvironments11 = ClosedEnum<
  typeof ConnectCreateConnectorRequestEnvironments11
>;

/**
 * A built-in environment name or the stable env_* ID of a custom environment.
 */
export type ConnectCreateConnectorRequest1Environments =
  | ConnectCreateConnectorRequestEnvironments11
  | string;

export type ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment = {
  /**
   * Project that receives triggers. During connector creation, omit it to use the top-level projectId.
   */
  projectId?: string | undefined;
  /**
   * 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 ConnectCreateConnectorRequestTriggerDestinationBranch = {
  /**
   * Project that receives triggers. During connector creation, omit it to use the top-level projectId.
   */
  projectId?: string | undefined;
  /**
   * 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 ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment = {
  /**
   * Project that receives triggers. During connector creation, omit it to use the top-level projectId.
   */
  projectId?: string | undefined;
  /**
   * Route path on the linked project that receives forwarded trigger requests.
   */
  path?: string | undefined;
};

/**
 * Initial trigger destination. Requires triggers to be enabled and a projectId here or at the top level. Connector responses expose the resulting set as triggerDestinations. Replace the complete set with PATCH /v1/connect/connectors/{connector}/trigger-destinations.
 */
export type TriggerDestination =
  | ConnectCreateConnectorRequestTriggerDestinationBranch
  | ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment
  | ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment;

export type FullConfiguration = {
  /**
   * Provider configuration. With type, provide the complete configuration for that type. With service and connectionMethod, provide only credentials and preferences; Connect supplies the type, endpoints, templates, and defaults. Other connector types accept an arbitrary object.
   */
  data: ConnectConnectorCreateData;
  /**
   * SHA-1 digest of a PNG or JPEG icon that is at least 640 by 640 pixels. This field does not accept a URL or image bytes.
   *
   * @remarks
   *
   * First compute the digest and upload the raw image with [POST /v2/files](https://vercel.com/docs/rest-api/deployments/upload-deployment-files). Send `Content-Length` and the same 40-character digest in `x-vercel-digest`. Then set `icon` to that digest.
   *
   * ```js
   * import { createHash } from 'node:crypto';
   * import { readFile } from 'node:fs/promises';
   *
   * const VERCEL_TOKEN = process.env.VERCEL_TOKEN;
   * const connectorId = 'scl_...';
   * const bytes = await readFile('icon.png');
   * const digest = createHash('sha1').update(bytes).digest('hex');
   *
   * await fetch('https://api.vercel.com/v2/files', {
   *   method: 'POST',
   *   headers: {
   *     Authorization: `Bearer ${VERCEL_TOKEN}`,
   *     'Content-Type': 'application/octet-stream',
   *     'Content-Length': String(bytes.length),
   *     'x-vercel-digest': digest,
   *   },
   *   body: bytes,
   * });
   *
   * await fetch(`https://api.vercel.com/v2/connect/connectors/${connectorId}`, {
   *   method: 'PATCH',
   *   headers: {
   *     Authorization: `Bearer ${VERCEL_TOKEN}`,
   *     'Content-Type': 'application/json',
   *   },
   *   body: JSON.stringify({ icon: digest }),
   * });
   * ```
   */
  icon?: string | undefined;
  /**
   * Branding background color (6-digit hex, for example
   */
  backgroundColor?: string | undefined;
  /**
   * Branding accent color (6-digit hex, for example
   */
  accentColor?: string | undefined;
  /**
   * Connector implementation type for full configuration. Known types: api-key, discord, github, linear, linq, microsoft-entra, oauth, photon, salesforce, sendblue, slack, snowflake, snowflake-wif. Optional when service and connectionMethod select the type.
   */
  type: string;
  /**
   * Service slug or URL for which the connector is used. Required when connectionMethod is set. Service alone does not enable preset configuration.
   */
  service?: string | undefined;
  /**
   * Connection method slug of the service. Use it with service to select preset configuration.
   */
  connectionMethod?: string | undefined;
  /**
   * Values for the selected connection method's template fields. Requires connectionMethod.
   */
  params?: { [k: string]: string } | undefined;
  /**
   * Which of the service's targets this connector is for. Requires \"connectionMethod\" and must be one that method serves. Optional.
   */
  target?: string | undefined;
  /**
   * Optional team-scoped unique identifier for the connector. If omitted or empty, Connect generates a value.
   */
  uid?: string | undefined;
  /**
   * Connector name. The value is trimmed and cannot contain control characters. If omitted or empty, the project name is used. A name or projectId is required. API key connectors require name.
   */
  name?: string | undefined;
  /**
   * Project to connect during creation. If environments is omitted, the connection uses development, preview, and production.
   */
  projectId?: string | undefined;
  /**
   * Environments for the project connection. Requires projectId. Use one or more built-in environment names or stable custom environment IDs that belong to the project. Duplicate values are accepted and removed.
   */
  environments?:
    | Array<ConnectCreateConnectorRequestEnvironments11 | string>
    | undefined;
  /**
   * Whether the triggers are enabled for this connector.
   */
  triggers?: boolean | undefined;
  /**
   * Initial trigger destination. Requires triggers to be enabled and a projectId here or at the top level. Connector responses expose the resulting set as triggerDestinations. Replace the complete set with PATCH /v1/connect/connectors/{connector}/trigger-destinations.
   */
  triggerDestination?:
    | ConnectCreateConnectorRequestTriggerDestinationBranch
    | ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment
    | ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment
    | undefined;
  /**
   * Default trigger events for this connector.
   */
  events?: Array<string> | undefined;
};

/**
 * Create a connector with full provider configuration or with a known service connection method.
 */
export type ConnectCreateConnectorRequest =
  | PresetConfiguration
  | FullConfiguration;

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

/** @internal */
export type ConnectCreateConnectorRequestEnvironments$Outbound =
  | string
  | string;

/** @internal */
export const ConnectCreateConnectorRequestEnvironments$outboundSchema:
  z.ZodType<
    ConnectCreateConnectorRequestEnvironments$Outbound,
    z.ZodTypeDef,
    ConnectCreateConnectorRequestEnvironments
  > = smartUnion([
    ConnectCreateConnectorRequestEnvironments1$outboundSchema,
    z.string(),
  ]);

export function connectCreateConnectorRequestEnvironmentsToJSON(
  connectCreateConnectorRequestEnvironments:
    ConnectCreateConnectorRequestEnvironments,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequestEnvironments$outboundSchema.parse(
      connectCreateConnectorRequestEnvironments,
    ),
  );
}

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

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

export function triggerDestinationCustomEnvironmentToJSON(
  triggerDestinationCustomEnvironment: TriggerDestinationCustomEnvironment,
): string {
  return JSON.stringify(
    TriggerDestinationCustomEnvironment$outboundSchema.parse(
      triggerDestinationCustomEnvironment,
    ),
  );
}

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

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

export function triggerDestinationBranchToJSON(
  triggerDestinationBranch: TriggerDestinationBranch,
): string {
  return JSON.stringify(
    TriggerDestinationBranch$outboundSchema.parse(triggerDestinationBranch),
  );
}

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

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

export function triggerDestinationDefaultDeploymentToJSON(
  triggerDestinationDefaultDeployment: TriggerDestinationDefaultDeployment,
): string {
  return JSON.stringify(
    TriggerDestinationDefaultDeployment$outboundSchema.parse(
      triggerDestinationDefaultDeployment,
    ),
  );
}

/** @internal */
export type ConnectCreateConnectorRequestTriggerDestination$Outbound =
  | TriggerDestinationBranch$Outbound
  | TriggerDestinationCustomEnvironment$Outbound
  | TriggerDestinationDefaultDeployment$Outbound;

/** @internal */
export const ConnectCreateConnectorRequestTriggerDestination$outboundSchema:
  z.ZodType<
    ConnectCreateConnectorRequestTriggerDestination$Outbound,
    z.ZodTypeDef,
    ConnectCreateConnectorRequestTriggerDestination
  > = smartUnion([
    z.lazy(() => TriggerDestinationBranch$outboundSchema),
    z.lazy(() => TriggerDestinationCustomEnvironment$outboundSchema),
    z.lazy(() => TriggerDestinationDefaultDeployment$outboundSchema),
  ]);

export function connectCreateConnectorRequestTriggerDestinationToJSON(
  connectCreateConnectorRequestTriggerDestination:
    ConnectCreateConnectorRequestTriggerDestination,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequestTriggerDestination$outboundSchema.parse(
      connectCreateConnectorRequestTriggerDestination,
    ),
  );
}

/** @internal */
export type PresetConfiguration$Outbound = {
  data: ConnectConnectorCreateData$Outbound;
  icon?: string | undefined;
  backgroundColor?: string | undefined;
  accentColor?: string | undefined;
  type?: string | undefined;
  service: string;
  connectionMethod: string;
  params?: { [k: string]: string } | undefined;
  target?: string | undefined;
  uid?: string | undefined;
  name?: string | undefined;
  projectId?: string | undefined;
  environments?: Array<string | string> | undefined;
  triggers?: boolean | undefined;
  triggerDestination?:
    | TriggerDestinationBranch$Outbound
    | TriggerDestinationCustomEnvironment$Outbound
    | TriggerDestinationDefaultDeployment$Outbound
    | undefined;
  events?: Array<string> | undefined;
};

/** @internal */
export const PresetConfiguration$outboundSchema: z.ZodType<
  PresetConfiguration$Outbound,
  z.ZodTypeDef,
  PresetConfiguration
> = z.object({
  data: ConnectConnectorCreateData$outboundSchema,
  icon: z.string().optional(),
  backgroundColor: z.string().optional(),
  accentColor: z.string().optional(),
  type: z.string().optional(),
  service: z.string(),
  connectionMethod: z.string(),
  params: z.record(z.string()).optional(),
  target: z.string().optional(),
  uid: z.string().optional(),
  name: z.string().optional(),
  projectId: z.string().optional(),
  environments: z.array(
    smartUnion([
      ConnectCreateConnectorRequestEnvironments1$outboundSchema,
      z.string(),
    ]),
  ).optional(),
  triggers: z.boolean().optional(),
  triggerDestination: smartUnion([
    z.lazy(() => TriggerDestinationBranch$outboundSchema),
    z.lazy(() => TriggerDestinationCustomEnvironment$outboundSchema),
    z.lazy(() => TriggerDestinationDefaultDeployment$outboundSchema),
  ]).optional(),
  events: z.array(z.string()).optional(),
});

export function presetConfigurationToJSON(
  presetConfiguration: PresetConfiguration,
): string {
  return JSON.stringify(
    PresetConfiguration$outboundSchema.parse(presetConfiguration),
  );
}

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

/** @internal */
export type ConnectCreateConnectorRequest1Environments$Outbound =
  | string
  | string;

/** @internal */
export const ConnectCreateConnectorRequest1Environments$outboundSchema:
  z.ZodType<
    ConnectCreateConnectorRequest1Environments$Outbound,
    z.ZodTypeDef,
    ConnectCreateConnectorRequest1Environments
  > = smartUnion([
    ConnectCreateConnectorRequestEnvironments11$outboundSchema,
    z.string(),
  ]);

export function connectCreateConnectorRequest1EnvironmentsToJSON(
  connectCreateConnectorRequest1Environments:
    ConnectCreateConnectorRequest1Environments,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequest1Environments$outboundSchema.parse(
      connectCreateConnectorRequest1Environments,
    ),
  );
}

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

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

export function connectCreateConnectorRequestTriggerDestinationCustomEnvironmentToJSON(
  connectCreateConnectorRequestTriggerDestinationCustomEnvironment:
    ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment$outboundSchema
      .parse(connectCreateConnectorRequestTriggerDestinationCustomEnvironment),
  );
}

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

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

export function connectCreateConnectorRequestTriggerDestinationBranchToJSON(
  connectCreateConnectorRequestTriggerDestinationBranch:
    ConnectCreateConnectorRequestTriggerDestinationBranch,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequestTriggerDestinationBranch$outboundSchema.parse(
      connectCreateConnectorRequestTriggerDestinationBranch,
    ),
  );
}

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

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

export function connectCreateConnectorRequestTriggerDestinationDefaultDeploymentToJSON(
  connectCreateConnectorRequestTriggerDestinationDefaultDeployment:
    ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment$outboundSchema
      .parse(connectCreateConnectorRequestTriggerDestinationDefaultDeployment),
  );
}

/** @internal */
export type TriggerDestination$Outbound =
  | ConnectCreateConnectorRequestTriggerDestinationBranch$Outbound
  | ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment$Outbound
  | ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment$Outbound;

/** @internal */
export const TriggerDestination$outboundSchema: z.ZodType<
  TriggerDestination$Outbound,
  z.ZodTypeDef,
  TriggerDestination
> = smartUnion([
  z.lazy(() =>
    ConnectCreateConnectorRequestTriggerDestinationBranch$outboundSchema
  ),
  z.lazy(() =>
    ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment$outboundSchema
  ),
  z.lazy(() =>
    ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment$outboundSchema
  ),
]);

export function triggerDestinationToJSON(
  triggerDestination: TriggerDestination,
): string {
  return JSON.stringify(
    TriggerDestination$outboundSchema.parse(triggerDestination),
  );
}

/** @internal */
export type FullConfiguration$Outbound = {
  data: ConnectConnectorCreateData$Outbound;
  icon?: string | undefined;
  backgroundColor?: string | undefined;
  accentColor?: string | undefined;
  type: string;
  service?: string | undefined;
  connectionMethod?: string | undefined;
  params?: { [k: string]: string } | undefined;
  target?: string | undefined;
  uid?: string | undefined;
  name?: string | undefined;
  projectId?: string | undefined;
  environments?: Array<string | string> | undefined;
  triggers?: boolean | undefined;
  triggerDestination?:
    | ConnectCreateConnectorRequestTriggerDestinationBranch$Outbound
    | ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment$Outbound
    | ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment$Outbound
    | undefined;
  events?: Array<string> | undefined;
};

/** @internal */
export const FullConfiguration$outboundSchema: z.ZodType<
  FullConfiguration$Outbound,
  z.ZodTypeDef,
  FullConfiguration
> = z.object({
  data: ConnectConnectorCreateData$outboundSchema,
  icon: z.string().optional(),
  backgroundColor: z.string().optional(),
  accentColor: z.string().optional(),
  type: z.string(),
  service: z.string().optional(),
  connectionMethod: z.string().optional(),
  params: z.record(z.string()).optional(),
  target: z.string().optional(),
  uid: z.string().optional(),
  name: z.string().optional(),
  projectId: z.string().optional(),
  environments: z.array(
    smartUnion([
      ConnectCreateConnectorRequestEnvironments11$outboundSchema,
      z.string(),
    ]),
  ).optional(),
  triggers: z.boolean().optional(),
  triggerDestination: smartUnion([
    z.lazy(() =>
      ConnectCreateConnectorRequestTriggerDestinationBranch$outboundSchema
    ),
    z.lazy(() =>
      ConnectCreateConnectorRequestTriggerDestinationCustomEnvironment$outboundSchema
    ),
    z.lazy(() =>
      ConnectCreateConnectorRequestTriggerDestinationDefaultDeployment$outboundSchema
    ),
  ]).optional(),
  events: z.array(z.string()).optional(),
});

export function fullConfigurationToJSON(
  fullConfiguration: FullConfiguration,
): string {
  return JSON.stringify(
    FullConfiguration$outboundSchema.parse(fullConfiguration),
  );
}

/** @internal */
export type ConnectCreateConnectorRequest$Outbound =
  | PresetConfiguration$Outbound
  | FullConfiguration$Outbound;

/** @internal */
export const ConnectCreateConnectorRequest$outboundSchema: z.ZodType<
  ConnectCreateConnectorRequest$Outbound,
  z.ZodTypeDef,
  ConnectCreateConnectorRequest
> = smartUnion([
  z.lazy(() => PresetConfiguration$outboundSchema),
  z.lazy(() => FullConfiguration$outboundSchema),
]);

export function connectCreateConnectorRequestToJSON(
  connectCreateConnectorRequest: ConnectCreateConnectorRequest,
): string {
  return JSON.stringify(
    ConnectCreateConnectorRequest$outboundSchema.parse(
      connectCreateConnectorRequest,
    ),
  );
}
