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

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

export type TypeSnowflakeWif = {
  clientName: string;
  accountIdentifier?: string | undefined;
  extras?: { [k: string]: any } | undefined;
};

export type TypeSnowflake = {
  clientName: string;
  accountIdentifier: string;
  defaultSessionRole?: string | undefined;
  extras?: { [k: string]: any } | undefined;
};

export type SlackTeam = {
  id: string;
  name?: string | undefined;
  domain?: string | undefined;
};

export type TypeSlack = {
  appId: string;
  appName: string;
  clientId: string;
  clientSecret: string;
  slackTeam?: SlackTeam | undefined;
  signingSecret?: string | undefined;
  verificationToken?: string | undefined;
  botScopes?: Array<string> | undefined;
  userScopes?: Array<string> | undefined;
  extras?: { [k: string]: any } | undefined;
};

export type TypeSalesforce = {
  consumerKey: string;
  consumerSecret: string;
  loginHost: string;
};

export type OwnerOrganization = {
  id: string;
  slug: string;
  name: string;
  logoUrl?: string | null | undefined;
};

export type Application = {
  id: string;
  clientId: string;
  name: string;
  description?: string | null | undefined;
  developer?: string | null | undefined;
  developerUrl?: string | null | undefined;
  imageUrl?: string | null | undefined;
  redirectUris?: Array<string> | undefined;
  distribution?: string | null | undefined;
  webhookResourceTypes?: Array<string> | undefined;
  webhookUrl?: string | null | undefined;
  webhookEnabled?: boolean | undefined;
  createdAt?: string | undefined;
  updatedAt?: string | undefined;
};

export type TypeLinear = {
  appId?: string | undefined;
  appName?: string | undefined;
  clientId: string;
  clientSecret: string;
  webhookSecret?: string | undefined;
  appScopes?: Array<string> | undefined;
  userScopes?: Array<string> | undefined;
  ownerOrganization?: OwnerOrganization | undefined;
  application?: Application | undefined;
  extras?: { [k: string]: any } | undefined;
};

export const DataType = {
  UserLower: "user",
  OrganizationLower: "organization",
  UserMixed: "User",
  OrganizationMixed: "Organization",
} as const;
export type DataType = ClosedEnum<typeof DataType>;

export type Owner = {
  type: DataType;
  id: number;
  slug: string;
  name?: string | undefined;
};

export type TypeGithub = {
  appId: number;
  appSlug: string;
  appName: string;
  clientId: string;
  owner?: Owner | undefined;
  clientSecret?: string | undefined;
  privateKeyPem?: string | undefined;
  webhookSecret?: string | undefined;
  extras?: { [k: string]: any } | undefined;
};

export type Values = {
  value: string;
  scope?: string | undefined;
  /**
   * The timestamp when the API key value expires in milliseconds.
   */
  expiresAt?: number | undefined;
};

export type TypeApiKey = {
  values: Array<Values>;
};

export const Use = {
  Sig: "sig",
  Enc: "enc",
} as const;
export type Use = ClosedEnum<typeof Use>;

export type Keys = {
  kty: string;
  kid?: string | undefined;
  use?: Use | undefined;
  keyOps?: Array<string> | undefined;
  alg?: string | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

export type Jwks = {
  keys: Array<Keys>;
  additionalProperties?: { [k: string]: any } | undefined;
};

export type ServerConfig = {
  issuer?: string | undefined;
  authorizationEndpoint?: string | undefined;
  tokenEndpoint?: string | undefined;
  userinfoEndpoint?: string | undefined;
  jwksUri?: string | undefined;
  jwks?: Jwks | undefined;
  revocationEndpoint?: string | undefined;
  introspectionEndpoint?: string | undefined;
  endSessionEndpoint?: string | undefined;
  deviceAuthorizationEndpoint?: string | undefined;
  registrationEndpoint?: string | undefined;
  responseTypesSupported?: Array<string> | undefined;
  tokenEndpointAuthMethodsSupported?: Array<string> | undefined;
  tokenEndpointAuthSigningAlgValuesSupported?: Array<string> | undefined;
  scopesSupported?: Array<string> | undefined;
  grantTypesSupported?: Array<string> | undefined;
  responseModesSupported?: Array<string> | undefined;
  subjectTypesSupported?: Array<string> | undefined;
  idTokenSigningAlgValuesSupported?: Array<string> | undefined;
  idTokenEncryptionAlgValuesSupported?: Array<string> | undefined;
  idTokenEncryptionEncValuesSupported?: Array<string> | undefined;
  claimTypesSupported?: Array<string> | undefined;
  claimsSupported?: Array<string> | undefined;
  codeChallengeMethodsSupported?: Array<string> | undefined;
  promptValuesSupported?: Array<string> | undefined;
  claimsParameterSupported?: boolean | undefined;
  requestParameterSupported?: boolean | undefined;
  requestUriParameterSupported?: boolean | undefined;
  requireRequestUriRegistration?: boolean | undefined;
  serviceDocumentation?: string | undefined;
  opPolicyUri?: string | undefined;
  opTosUri?: string | undefined;
  logoUri?: string | undefined;
  clientIdMetadataDocumentSupported?: boolean | undefined;
  authorizationDetailsTypesSupported?: Array<string> | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

export type UserAuthorization = {
  enabled: boolean;
  /**
   * Default scopes to request when token params specify scopes: ["*"].
   */
  scopes?: Array<string> | undefined;
};

export type RefreshTokens = {
  enabled: boolean;
};

export type ClientCredentials = {
  enabled: boolean;
  /**
   * Default scopes to request when token params specify scopes: ["*"].
   */
  scopes?: Array<string> | undefined;
};

export type JwtBearer = {
  enabled?: boolean | undefined;
  /**
   * Default scopes to request when token params specify scopes: ["*"].
   */
  scopes?: Array<string> | undefined;
  sub?: string | undefined;
  iss?: string | undefined;
  aud?: string | undefined;
  additionalClaims?: { [k: string]: any } | undefined;
  ttl?: number | undefined;
  useClientCredentials?: boolean | undefined;
};

export type TypeOauth = {
  serverUrl?: string | undefined;
  serverConfig?: ServerConfig | undefined;
  clientId: string;
  clientSecret?: string | undefined;
  tokenEndpointAuthMethod?: string | undefined;
  responseType?: string | undefined;
  pkceRequired?: boolean | undefined;
  codeChallengeMethod?: string | undefined;
  userAuthorization?: UserAuthorization | undefined;
  refreshTokens?: RefreshTokens | undefined;
  clientCredentials?: ClientCredentials | undefined;
  defaultAudience?: string | undefined;
  authorizationUrlParams?: { [k: string]: string } | undefined;
  jwtBearer?: JwtBearer | undefined;
};

export type CreateConnectorData =
  | TypeGithub
  | TypeSlack
  | TypeSalesforce
  | TypeLinear
  | TypeSnowflake
  | TypeOauth
  | TypeApiKey
  | TypeSnowflakeWif
  | { [k: string]: any };

export type CreateConnectorRequestBody = {
  /**
   * Known types: api-key, github, linear, oauth, salesforce, slack, snowflake.
   */
  type: string;
  /**
   * Service slug or URL for which the connector is used.
   */
  service?: string | undefined;
  uid?: string | undefined;
  name?: string | undefined;
  /**
   * Link to the specified project when specified. See environments.
   */
  projectId?: string | undefined;
  /**
   * Use these environments when linking to the project specified by the projectId.
   */
  environments?: Array<string> | undefined;
  /**
   * Whether the triggers are enabled for this connector.
   */
  triggers?: boolean | undefined;
  /**
   * The list of the defaults trigger events for this connector.
   */
  events?: Array<string> | undefined;
  /**
   * Branding icon. Either a SHA-1 hash already uploaded to the Vercel avatar service or an https:// URL that will be downloaded and rehosted.
   */
  icon?: string | undefined;
  /**
   * Branding background color (6-digit hex, e.g. "#000000").
   */
  backgroundColor?: string | undefined;
  /**
   * Branding accent color (6-digit hex, e.g. "#000000").
   */
  accentColor?: string | undefined;
  data:
    | TypeGithub
    | TypeSlack
    | TypeSalesforce
    | TypeLinear
    | TypeSnowflake
    | TypeOauth
    | TypeApiKey
    | TypeSnowflakeWif
    | { [k: string]: any };
};

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

/**
 * Principal that originally created the connector — either a Vercel user (interactive dashboard / CLI flow) or a Vercel deployment (OIDC-authenticated project, used by runtime auto-provisioning). See {@link ConnexPrincipal}. Optional: pre-existing rows from before this shape was introduced may carry no attribution at all.
 */
export type CreatedBy2 = {
  type: "project";
  id: string;
  environment: CreatedByEnvironment;
};

/**
 * Principal that originally created the connector — either a Vercel user (interactive dashboard / CLI flow) or a Vercel deployment (OIDC-authenticated project, used by runtime auto-provisioning). See {@link ConnexPrincipal}. Optional: pre-existing rows from before this shape was introduced may carry no attribution at all.
 */
export type CreatedBy1 = {
  type: "user";
  id: string;
};

export type CreatedBy = CreatedBy1 | CreatedBy2;

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

/**
 * Principal that most recently mutated the connector. Same shape as {@link createdBy} but tracks the most recent updater, not the original creator. At create time the two fields point at the same principal; they diverge on the first subsequent update.
 */
export type UpdatedBy2 = {
  type: "project";
  id: string;
  environment: UpdatedByEnvironment;
};

/**
 * Principal that most recently mutated the connector. Same shape as {@link createdBy} but tracks the most recent updater, not the original creator. At create time the two fields point at the same principal; they diverge on the first subsequent update.
 */
export type UpdatedBy1 = {
  type: "user";
  id: string;
};

export type UpdatedBy = UpdatedBy1 | UpdatedBy2;

export const CreateConnectorType = {
  ApiKey: "api-key",
  Custom: "custom",
  Github: "github",
  Linear: "linear",
  Oauth: "oauth",
  Salesforce: "salesforce",
  Slack: "slack",
  Snowflake: "snowflake",
  SnowflakeWif: "snowflake-wif",
} as const;
export type CreateConnectorType = ClosedEnum<typeof CreateConnectorType>;

export type AppTokens = {
  crossInstallation: boolean;
  supportsRefinement: boolean;
  /**
   * True when changing app token grants requires reinstalling the app, so tokens cannot be partitioned independently by requester environment.
   */
  requiresReinstallation?: boolean | undefined;
  /**
   * Known allowed app-level scopes. For Slack this is the bot scope set configured on the app; for OAuth it is `scopes_supported` from the server's discovery document.
   */
  scopes?: Array<string> | undefined;
  supportedAuthorizationDetails?: Array<string> | undefined;
};

export type UserTokens = {
  crossInstallation: boolean;
  supportsRefinement: boolean;
  /**
   * Known allowed user-level scopes. For Slack this is the user scope set configured on the app; for OAuth it is `scopes_supported` from the server's discovery document.
   */
  scopes?: Array<string> | undefined;
  supportedAuthorizationDetails?: Array<string> | undefined;
};

export const SupportsIcon = {
  False: "false",
  Maybe: "maybe",
  True: "true",
} as const;
export type SupportsIcon = ClosedEnum<typeof SupportsIcon>;

/**
 * Incoming trigger configuration. Only present when enabled.
 */
export type Triggers = {
  enabled: boolean;
};

/**
 * Destinations that incoming triggers should be forwarded to. Limited to `MAX_CONNEX_TRIGGER_DESTINATIONS` entries.
 */
export type TriggerDestinations = {
  projectId: string;
  branch?: string | undefined;
  path?: string | undefined;
};

export type CreateConnectorProject = {
  id: string;
  name: string;
};

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

export type CreateConnectorItems = {
  clientId: string;
  projectId: string;
  project?: CreateConnectorProject | undefined;
  environments: Array<CreateConnectorEnvironments>;
  createdAt: number;
  updatedAt: number;
};

/**
 * Set by `?include=projects`. Capped at 100 per client.
 */
export type CreateConnectorProjects = {
  items: Array<CreateConnectorItems>;
  hasMore: boolean;
  cursor?: string | null | undefined;
};

/**
 * Optional expansions populated by `?include=...` on the list endpoint.
 */
export type Includes = {
  /**
   * Set by `?include=projects`. Capped at 100 per client.
   */
  projects?: CreateConnectorProjects | undefined;
};

export type CreateConnectorResponseBody = {
  id: string;
  ownerId: string;
  createdAt: number;
  updatedAt: number;
  deletedAt?: number | undefined;
  createdBy?: CreatedBy1 | CreatedBy2 | undefined;
  updatedBy?: UpdatedBy1 | UpdatedBy2 | undefined;
  public: boolean;
  uid: string;
  type: CreateConnectorType;
  /**
   * Best-effort identifier of the third-party service this client represents, independent of `type`. Examples: `'slack'`, `'mcp.linear.app'`, `'auth.example.com'`. Always non-empty on the API response — falls back through `storedClient.service ?? typeDef.service ?? typeDef.type`.
   */
  service: string;
  name: string;
  clientUrl?: string | null | undefined;
  /**
   * Redirect URI registered with the third-party service for this client, if any. Used by `startAuthorization`/`startInstallation` to replay the exact URI back to the provider's token endpoint. Absent on clients created before this field was introduced; those callers fall back to the `https://connect.vercel.com/callback` default.
   */
  redirectUri?: string | undefined;
  defaultInstallationId?: string | undefined;
  data: { [k: string]: any };
  typeName: string;
  typeIcon?: string | undefined;
  website?: string | undefined;
  devsite?: string | undefined;
  docsite?: string | undefined;
  /**
   * Client branding icon. SHA-1 hash that resolves to the uploaded icon via the Vercel avatar service. Clients render this with `https://vercel.com/api/www/avatar/{icon}`.
   */
  icon?: string | undefined;
  /**
   * Hex background color (e.g., `#000000`) for branding.
   */
  backgroundColor?: string | undefined;
  /**
   * Hex accent color (e.g., `#000000`) for branding.
   */
  accentColor?: string | undefined;
  supportedSubjectTypes: Array<string>;
  appTokens?: AppTokens | undefined;
  userTokens?: UserTokens | undefined;
  supportsInstallation: boolean;
  supportsRevocation: boolean;
  ownerTenantId?: string | undefined;
  /**
   * Whether this client type supports trigger webhooks. Derived from the type definition; indicates that `triggers` and `triggerDestinations` may be meaningful for this client.
   */
  supportsTriggers: boolean;
  supportsIcon: SupportsIcon;
  /**
   * Incoming trigger configuration. Only present when enabled.
   */
  triggers?: Triggers | undefined;
  /**
   * Known events this client subscribes to (e.g. Slack bot events, GitHub webhook events). Names are type-specific and validated by the managed-create flow when forwarded to the third-party service.
   */
  events?: Array<string> | undefined;
  /**
   * Destinations that incoming triggers should be forwarded to. Limited to `MAX_CONNEX_TRIGGER_DESTINATIONS` entries.
   */
  triggerDestinations?: Array<TriggerDestinations> | undefined;
  /**
   * Optional expansions populated by `?include=...` on the list endpoint.
   */
  includes?: Includes | undefined;
};

/** @internal */
export type TypeSnowflakeWif$Outbound = {
  clientName: string;
  accountIdentifier?: string | undefined;
  extras?: { [k: string]: any } | undefined;
};

/** @internal */
export const TypeSnowflakeWif$outboundSchema: z.ZodType<
  TypeSnowflakeWif$Outbound,
  z.ZodTypeDef,
  TypeSnowflakeWif
> = z.object({
  clientName: z.string(),
  accountIdentifier: z.string().optional(),
  extras: z.record(z.any()).optional(),
});

export function typeSnowflakeWifToJSON(
  typeSnowflakeWif: TypeSnowflakeWif,
): string {
  return JSON.stringify(
    TypeSnowflakeWif$outboundSchema.parse(typeSnowflakeWif),
  );
}

/** @internal */
export type TypeSnowflake$Outbound = {
  clientName: string;
  accountIdentifier: string;
  defaultSessionRole?: string | undefined;
  extras?: { [k: string]: any } | undefined;
};

/** @internal */
export const TypeSnowflake$outboundSchema: z.ZodType<
  TypeSnowflake$Outbound,
  z.ZodTypeDef,
  TypeSnowflake
> = z.object({
  clientName: z.string(),
  accountIdentifier: z.string(),
  defaultSessionRole: z.string().optional(),
  extras: z.record(z.any()).optional(),
});

export function typeSnowflakeToJSON(typeSnowflake: TypeSnowflake): string {
  return JSON.stringify(TypeSnowflake$outboundSchema.parse(typeSnowflake));
}

/** @internal */
export type SlackTeam$Outbound = {
  id: string;
  name?: string | undefined;
  domain?: string | undefined;
};

/** @internal */
export const SlackTeam$outboundSchema: z.ZodType<
  SlackTeam$Outbound,
  z.ZodTypeDef,
  SlackTeam
> = z.object({
  id: z.string(),
  name: z.string().optional(),
  domain: z.string().optional(),
});

export function slackTeamToJSON(slackTeam: SlackTeam): string {
  return JSON.stringify(SlackTeam$outboundSchema.parse(slackTeam));
}

/** @internal */
export type TypeSlack$Outbound = {
  appId: string;
  appName: string;
  clientId: string;
  clientSecret: string;
  slackTeam?: SlackTeam$Outbound | undefined;
  signingSecret?: string | undefined;
  verificationToken?: string | undefined;
  botScopes?: Array<string> | undefined;
  userScopes?: Array<string> | undefined;
  extras?: { [k: string]: any } | undefined;
};

/** @internal */
export const TypeSlack$outboundSchema: z.ZodType<
  TypeSlack$Outbound,
  z.ZodTypeDef,
  TypeSlack
> = z.object({
  appId: z.string(),
  appName: z.string(),
  clientId: z.string(),
  clientSecret: z.string(),
  slackTeam: z.lazy(() => SlackTeam$outboundSchema).optional(),
  signingSecret: z.string().optional(),
  verificationToken: z.string().optional(),
  botScopes: z.array(z.string()).optional(),
  userScopes: z.array(z.string()).optional(),
  extras: z.record(z.any()).optional(),
});

export function typeSlackToJSON(typeSlack: TypeSlack): string {
  return JSON.stringify(TypeSlack$outboundSchema.parse(typeSlack));
}

/** @internal */
export type TypeSalesforce$Outbound = {
  consumerKey: string;
  consumerSecret: string;
  loginHost: string;
};

/** @internal */
export const TypeSalesforce$outboundSchema: z.ZodType<
  TypeSalesforce$Outbound,
  z.ZodTypeDef,
  TypeSalesforce
> = z.object({
  consumerKey: z.string(),
  consumerSecret: z.string(),
  loginHost: z.string(),
});

export function typeSalesforceToJSON(typeSalesforce: TypeSalesforce): string {
  return JSON.stringify(TypeSalesforce$outboundSchema.parse(typeSalesforce));
}

/** @internal */
export type OwnerOrganization$Outbound = {
  id: string;
  slug: string;
  name: string;
  logoUrl?: string | null | undefined;
};

/** @internal */
export const OwnerOrganization$outboundSchema: z.ZodType<
  OwnerOrganization$Outbound,
  z.ZodTypeDef,
  OwnerOrganization
> = z.object({
  id: z.string(),
  slug: z.string(),
  name: z.string(),
  logoUrl: z.nullable(z.string()).optional(),
});

export function ownerOrganizationToJSON(
  ownerOrganization: OwnerOrganization,
): string {
  return JSON.stringify(
    OwnerOrganization$outboundSchema.parse(ownerOrganization),
  );
}

/** @internal */
export type Application$Outbound = {
  id: string;
  clientId: string;
  name: string;
  description?: string | null | undefined;
  developer?: string | null | undefined;
  developerUrl?: string | null | undefined;
  imageUrl?: string | null | undefined;
  redirectUris?: Array<string> | undefined;
  distribution?: string | null | undefined;
  webhookResourceTypes?: Array<string> | undefined;
  webhookUrl?: string | null | undefined;
  webhookEnabled?: boolean | undefined;
  createdAt?: string | undefined;
  updatedAt?: string | undefined;
};

/** @internal */
export const Application$outboundSchema: z.ZodType<
  Application$Outbound,
  z.ZodTypeDef,
  Application
> = z.object({
  id: z.string(),
  clientId: z.string(),
  name: z.string(),
  description: z.nullable(z.string()).optional(),
  developer: z.nullable(z.string()).optional(),
  developerUrl: z.nullable(z.string()).optional(),
  imageUrl: z.nullable(z.string()).optional(),
  redirectUris: z.array(z.string()).optional(),
  distribution: z.nullable(z.string()).optional(),
  webhookResourceTypes: z.array(z.string()).optional(),
  webhookUrl: z.nullable(z.string()).optional(),
  webhookEnabled: z.boolean().optional(),
  createdAt: z.string().optional(),
  updatedAt: z.string().optional(),
});

export function applicationToJSON(application: Application): string {
  return JSON.stringify(Application$outboundSchema.parse(application));
}

/** @internal */
export type TypeLinear$Outbound = {
  appId?: string | undefined;
  appName?: string | undefined;
  clientId: string;
  clientSecret: string;
  webhookSecret?: string | undefined;
  appScopes?: Array<string> | undefined;
  userScopes?: Array<string> | undefined;
  ownerOrganization?: OwnerOrganization$Outbound | undefined;
  application?: Application$Outbound | undefined;
  extras?: { [k: string]: any } | undefined;
};

/** @internal */
export const TypeLinear$outboundSchema: z.ZodType<
  TypeLinear$Outbound,
  z.ZodTypeDef,
  TypeLinear
> = z.object({
  appId: z.string().optional(),
  appName: z.string().optional(),
  clientId: z.string(),
  clientSecret: z.string(),
  webhookSecret: z.string().optional(),
  appScopes: z.array(z.string()).optional(),
  userScopes: z.array(z.string()).optional(),
  ownerOrganization: z.lazy(() => OwnerOrganization$outboundSchema).optional(),
  application: z.lazy(() => Application$outboundSchema).optional(),
  extras: z.record(z.any()).optional(),
});

export function typeLinearToJSON(typeLinear: TypeLinear): string {
  return JSON.stringify(TypeLinear$outboundSchema.parse(typeLinear));
}

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

/** @internal */
export type Owner$Outbound = {
  type: string;
  id: number;
  slug: string;
  name?: string | undefined;
};

/** @internal */
export const Owner$outboundSchema: z.ZodType<
  Owner$Outbound,
  z.ZodTypeDef,
  Owner
> = z.object({
  type: DataType$outboundSchema,
  id: z.number().int(),
  slug: z.string(),
  name: z.string().optional(),
});

export function ownerToJSON(owner: Owner): string {
  return JSON.stringify(Owner$outboundSchema.parse(owner));
}

/** @internal */
export type TypeGithub$Outbound = {
  appId: number;
  appSlug: string;
  appName: string;
  clientId: string;
  owner?: Owner$Outbound | undefined;
  clientSecret?: string | undefined;
  privateKeyPem?: string | undefined;
  webhookSecret?: string | undefined;
  extras?: { [k: string]: any } | undefined;
};

/** @internal */
export const TypeGithub$outboundSchema: z.ZodType<
  TypeGithub$Outbound,
  z.ZodTypeDef,
  TypeGithub
> = z.object({
  appId: z.number().int(),
  appSlug: z.string(),
  appName: z.string(),
  clientId: z.string(),
  owner: z.lazy(() => Owner$outboundSchema).optional(),
  clientSecret: z.string().optional(),
  privateKeyPem: z.string().optional(),
  webhookSecret: z.string().optional(),
  extras: z.record(z.any()).optional(),
});

export function typeGithubToJSON(typeGithub: TypeGithub): string {
  return JSON.stringify(TypeGithub$outboundSchema.parse(typeGithub));
}

/** @internal */
export type Values$Outbound = {
  value: string;
  scope?: string | undefined;
  expiresAt?: number | undefined;
};

/** @internal */
export const Values$outboundSchema: z.ZodType<
  Values$Outbound,
  z.ZodTypeDef,
  Values
> = z.object({
  value: z.string(),
  scope: z.string().optional(),
  expiresAt: z.number().int().optional(),
});

export function valuesToJSON(values: Values): string {
  return JSON.stringify(Values$outboundSchema.parse(values));
}

/** @internal */
export type TypeApiKey$Outbound = {
  values: Array<Values$Outbound>;
};

/** @internal */
export const TypeApiKey$outboundSchema: z.ZodType<
  TypeApiKey$Outbound,
  z.ZodTypeDef,
  TypeApiKey
> = z.object({
  values: z.array(z.lazy(() => Values$outboundSchema)),
});

export function typeApiKeyToJSON(typeApiKey: TypeApiKey): string {
  return JSON.stringify(TypeApiKey$outboundSchema.parse(typeApiKey));
}

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

/** @internal */
export type Keys$Outbound = {
  kty: string;
  kid?: string | undefined;
  use?: string | undefined;
  key_ops?: Array<string> | undefined;
  alg?: string | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const Keys$outboundSchema: z.ZodType<Keys$Outbound, z.ZodTypeDef, Keys> =
  z.object({
    kty: z.string(),
    kid: z.string().optional(),
    use: Use$outboundSchema.optional(),
    keyOps: z.array(z.string()).optional(),
    alg: z.string().optional(),
    additionalProperties: z.record(z.any()).optional(),
  }).transform((v) => {
    return {
      ...v.additionalProperties,
      ...remap$(v, {
        keyOps: "key_ops",
        additionalProperties: null,
      }),
    };
  });

export function keysToJSON(keys: Keys): string {
  return JSON.stringify(Keys$outboundSchema.parse(keys));
}

/** @internal */
export type Jwks$Outbound = {
  keys: Array<Keys$Outbound>;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const Jwks$outboundSchema: z.ZodType<Jwks$Outbound, z.ZodTypeDef, Jwks> =
  z.object({
    keys: z.array(z.lazy(() => Keys$outboundSchema)),
    additionalProperties: z.record(z.any()).optional(),
  }).transform((v) => {
    return {
      ...v.additionalProperties,
      ...remap$(v, {
        additionalProperties: null,
      }),
    };
  });

export function jwksToJSON(jwks: Jwks): string {
  return JSON.stringify(Jwks$outboundSchema.parse(jwks));
}

/** @internal */
export type ServerConfig$Outbound = {
  issuer?: string | undefined;
  authorization_endpoint?: string | undefined;
  token_endpoint?: string | undefined;
  userinfo_endpoint?: string | undefined;
  jwks_uri?: string | undefined;
  jwks?: Jwks$Outbound | undefined;
  revocation_endpoint?: string | undefined;
  introspection_endpoint?: string | undefined;
  end_session_endpoint?: string | undefined;
  device_authorization_endpoint?: string | undefined;
  registration_endpoint?: string | undefined;
  response_types_supported?: Array<string> | undefined;
  token_endpoint_auth_methods_supported?: Array<string> | undefined;
  token_endpoint_auth_signing_alg_values_supported?: Array<string> | undefined;
  scopes_supported?: Array<string> | undefined;
  grant_types_supported?: Array<string> | undefined;
  response_modes_supported?: Array<string> | undefined;
  subject_types_supported?: Array<string> | undefined;
  id_token_signing_alg_values_supported?: Array<string> | undefined;
  id_token_encryption_alg_values_supported?: Array<string> | undefined;
  id_token_encryption_enc_values_supported?: Array<string> | undefined;
  claim_types_supported?: Array<string> | undefined;
  claims_supported?: Array<string> | undefined;
  code_challenge_methods_supported?: Array<string> | undefined;
  prompt_values_supported?: Array<string> | undefined;
  claims_parameter_supported?: boolean | undefined;
  request_parameter_supported?: boolean | undefined;
  request_uri_parameter_supported?: boolean | undefined;
  require_request_uri_registration?: boolean | undefined;
  service_documentation?: string | undefined;
  op_policy_uri?: string | undefined;
  op_tos_uri?: string | undefined;
  logo_uri?: string | undefined;
  client_id_metadata_document_supported?: boolean | undefined;
  authorization_details_types_supported?: Array<string> | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const ServerConfig$outboundSchema: z.ZodType<
  ServerConfig$Outbound,
  z.ZodTypeDef,
  ServerConfig
> = z.object({
  issuer: z.string().optional(),
  authorizationEndpoint: z.string().optional(),
  tokenEndpoint: z.string().optional(),
  userinfoEndpoint: z.string().optional(),
  jwksUri: z.string().optional(),
  jwks: z.lazy(() => Jwks$outboundSchema).optional(),
  revocationEndpoint: z.string().optional(),
  introspectionEndpoint: z.string().optional(),
  endSessionEndpoint: z.string().optional(),
  deviceAuthorizationEndpoint: z.string().optional(),
  registrationEndpoint: z.string().optional(),
  responseTypesSupported: z.array(z.string()).optional(),
  tokenEndpointAuthMethodsSupported: z.array(z.string()).optional(),
  tokenEndpointAuthSigningAlgValuesSupported: z.array(z.string()).optional(),
  scopesSupported: z.array(z.string()).optional(),
  grantTypesSupported: z.array(z.string()).optional(),
  responseModesSupported: z.array(z.string()).optional(),
  subjectTypesSupported: z.array(z.string()).optional(),
  idTokenSigningAlgValuesSupported: z.array(z.string()).optional(),
  idTokenEncryptionAlgValuesSupported: z.array(z.string()).optional(),
  idTokenEncryptionEncValuesSupported: z.array(z.string()).optional(),
  claimTypesSupported: z.array(z.string()).optional(),
  claimsSupported: z.array(z.string()).optional(),
  codeChallengeMethodsSupported: z.array(z.string()).optional(),
  promptValuesSupported: z.array(z.string()).optional(),
  claimsParameterSupported: z.boolean().optional(),
  requestParameterSupported: z.boolean().optional(),
  requestUriParameterSupported: z.boolean().optional(),
  requireRequestUriRegistration: z.boolean().optional(),
  serviceDocumentation: z.string().optional(),
  opPolicyUri: z.string().optional(),
  opTosUri: z.string().optional(),
  logoUri: z.string().optional(),
  clientIdMetadataDocumentSupported: z.boolean().optional(),
  authorizationDetailsTypesSupported: z.array(z.string()).optional(),
  additionalProperties: z.record(z.any()).optional(),
}).transform((v) => {
  return {
    ...v.additionalProperties,
    ...remap$(v, {
      authorizationEndpoint: "authorization_endpoint",
      tokenEndpoint: "token_endpoint",
      userinfoEndpoint: "userinfo_endpoint",
      jwksUri: "jwks_uri",
      revocationEndpoint: "revocation_endpoint",
      introspectionEndpoint: "introspection_endpoint",
      endSessionEndpoint: "end_session_endpoint",
      deviceAuthorizationEndpoint: "device_authorization_endpoint",
      registrationEndpoint: "registration_endpoint",
      responseTypesSupported: "response_types_supported",
      tokenEndpointAuthMethodsSupported:
        "token_endpoint_auth_methods_supported",
      tokenEndpointAuthSigningAlgValuesSupported:
        "token_endpoint_auth_signing_alg_values_supported",
      scopesSupported: "scopes_supported",
      grantTypesSupported: "grant_types_supported",
      responseModesSupported: "response_modes_supported",
      subjectTypesSupported: "subject_types_supported",
      idTokenSigningAlgValuesSupported: "id_token_signing_alg_values_supported",
      idTokenEncryptionAlgValuesSupported:
        "id_token_encryption_alg_values_supported",
      idTokenEncryptionEncValuesSupported:
        "id_token_encryption_enc_values_supported",
      claimTypesSupported: "claim_types_supported",
      claimsSupported: "claims_supported",
      codeChallengeMethodsSupported: "code_challenge_methods_supported",
      promptValuesSupported: "prompt_values_supported",
      claimsParameterSupported: "claims_parameter_supported",
      requestParameterSupported: "request_parameter_supported",
      requestUriParameterSupported: "request_uri_parameter_supported",
      requireRequestUriRegistration: "require_request_uri_registration",
      serviceDocumentation: "service_documentation",
      opPolicyUri: "op_policy_uri",
      opTosUri: "op_tos_uri",
      logoUri: "logo_uri",
      clientIdMetadataDocumentSupported:
        "client_id_metadata_document_supported",
      authorizationDetailsTypesSupported:
        "authorization_details_types_supported",
      additionalProperties: null,
    }),
  };
});

export function serverConfigToJSON(serverConfig: ServerConfig): string {
  return JSON.stringify(ServerConfig$outboundSchema.parse(serverConfig));
}

/** @internal */
export type UserAuthorization$Outbound = {
  enabled: boolean;
  scopes?: Array<string> | undefined;
};

/** @internal */
export const UserAuthorization$outboundSchema: z.ZodType<
  UserAuthorization$Outbound,
  z.ZodTypeDef,
  UserAuthorization
> = z.object({
  enabled: z.boolean(),
  scopes: z.array(z.string()).optional(),
});

export function userAuthorizationToJSON(
  userAuthorization: UserAuthorization,
): string {
  return JSON.stringify(
    UserAuthorization$outboundSchema.parse(userAuthorization),
  );
}

/** @internal */
export type RefreshTokens$Outbound = {
  enabled: boolean;
};

/** @internal */
export const RefreshTokens$outboundSchema: z.ZodType<
  RefreshTokens$Outbound,
  z.ZodTypeDef,
  RefreshTokens
> = z.object({
  enabled: z.boolean(),
});

export function refreshTokensToJSON(refreshTokens: RefreshTokens): string {
  return JSON.stringify(RefreshTokens$outboundSchema.parse(refreshTokens));
}

/** @internal */
export type ClientCredentials$Outbound = {
  enabled: boolean;
  scopes?: Array<string> | undefined;
};

/** @internal */
export const ClientCredentials$outboundSchema: z.ZodType<
  ClientCredentials$Outbound,
  z.ZodTypeDef,
  ClientCredentials
> = z.object({
  enabled: z.boolean(),
  scopes: z.array(z.string()).optional(),
});

export function clientCredentialsToJSON(
  clientCredentials: ClientCredentials,
): string {
  return JSON.stringify(
    ClientCredentials$outboundSchema.parse(clientCredentials),
  );
}

/** @internal */
export type JwtBearer$Outbound = {
  enabled?: boolean | undefined;
  scopes?: Array<string> | undefined;
  sub?: string | undefined;
  iss?: string | undefined;
  aud?: string | undefined;
  additionalClaims?: { [k: string]: any } | undefined;
  ttl?: number | undefined;
  useClientCredentials?: boolean | undefined;
};

/** @internal */
export const JwtBearer$outboundSchema: z.ZodType<
  JwtBearer$Outbound,
  z.ZodTypeDef,
  JwtBearer
> = z.object({
  enabled: z.boolean().optional(),
  scopes: z.array(z.string()).optional(),
  sub: z.string().optional(),
  iss: z.string().optional(),
  aud: z.string().optional(),
  additionalClaims: z.record(z.any()).optional(),
  ttl: z.number().optional(),
  useClientCredentials: z.boolean().optional(),
});

export function jwtBearerToJSON(jwtBearer: JwtBearer): string {
  return JSON.stringify(JwtBearer$outboundSchema.parse(jwtBearer));
}

/** @internal */
export type TypeOauth$Outbound = {
  serverUrl?: string | undefined;
  serverConfig?: ServerConfig$Outbound | undefined;
  clientId: string;
  clientSecret?: string | undefined;
  tokenEndpointAuthMethod: string;
  responseType?: string | undefined;
  pkceRequired?: boolean | undefined;
  codeChallengeMethod?: string | undefined;
  userAuthorization?: UserAuthorization$Outbound | undefined;
  refreshTokens?: RefreshTokens$Outbound | undefined;
  clientCredentials?: ClientCredentials$Outbound | undefined;
  defaultAudience?: string | undefined;
  authorizationUrlParams?: { [k: string]: string } | undefined;
  jwtBearer?: JwtBearer$Outbound | undefined;
};

/** @internal */
export const TypeOauth$outboundSchema: z.ZodType<
  TypeOauth$Outbound,
  z.ZodTypeDef,
  TypeOauth
> = z.object({
  serverUrl: z.string().optional(),
  serverConfig: z.lazy(() => ServerConfig$outboundSchema).optional(),
  clientId: z.string(),
  clientSecret: z.string().optional(),
  tokenEndpointAuthMethod: z.string().default("client_secret_post"),
  responseType: z.string().optional(),
  pkceRequired: z.boolean().optional(),
  codeChallengeMethod: z.string().optional(),
  userAuthorization: z.lazy(() => UserAuthorization$outboundSchema).optional(),
  refreshTokens: z.lazy(() => RefreshTokens$outboundSchema).optional(),
  clientCredentials: z.lazy(() => ClientCredentials$outboundSchema).optional(),
  defaultAudience: z.string().optional(),
  authorizationUrlParams: z.record(z.string()).optional(),
  jwtBearer: z.lazy(() => JwtBearer$outboundSchema).optional(),
});

export function typeOauthToJSON(typeOauth: TypeOauth): string {
  return JSON.stringify(TypeOauth$outboundSchema.parse(typeOauth));
}

/** @internal */
export type CreateConnectorData$Outbound =
  | TypeGithub$Outbound
  | TypeSlack$Outbound
  | TypeSalesforce$Outbound
  | TypeLinear$Outbound
  | TypeSnowflake$Outbound
  | TypeOauth$Outbound
  | TypeApiKey$Outbound
  | TypeSnowflakeWif$Outbound
  | { [k: string]: any };

/** @internal */
export const CreateConnectorData$outboundSchema: z.ZodType<
  CreateConnectorData$Outbound,
  z.ZodTypeDef,
  CreateConnectorData
> = smartUnion([
  z.lazy(() => TypeGithub$outboundSchema),
  z.lazy(() => TypeSlack$outboundSchema),
  z.lazy(() => TypeSalesforce$outboundSchema),
  z.lazy(() => TypeLinear$outboundSchema),
  z.lazy(() => TypeSnowflake$outboundSchema),
  z.lazy(() => TypeOauth$outboundSchema),
  z.lazy(() => TypeApiKey$outboundSchema),
  z.lazy(() => TypeSnowflakeWif$outboundSchema),
  z.record(z.any()),
]);

export function createConnectorDataToJSON(
  createConnectorData: CreateConnectorData,
): string {
  return JSON.stringify(
    CreateConnectorData$outboundSchema.parse(createConnectorData),
  );
}

/** @internal */
export type CreateConnectorRequestBody$Outbound = {
  type: string;
  service?: string | undefined;
  uid?: string | undefined;
  name?: string | undefined;
  projectId?: string | undefined;
  environments?: Array<string> | undefined;
  triggers?: boolean | undefined;
  events?: Array<string> | undefined;
  icon?: string | undefined;
  backgroundColor?: string | undefined;
  accentColor?: string | undefined;
  data:
    | TypeGithub$Outbound
    | TypeSlack$Outbound
    | TypeSalesforce$Outbound
    | TypeLinear$Outbound
    | TypeSnowflake$Outbound
    | TypeOauth$Outbound
    | TypeApiKey$Outbound
    | TypeSnowflakeWif$Outbound
    | { [k: string]: any };
};

/** @internal */
export const CreateConnectorRequestBody$outboundSchema: z.ZodType<
  CreateConnectorRequestBody$Outbound,
  z.ZodTypeDef,
  CreateConnectorRequestBody
> = z.object({
  type: z.string(),
  service: z.string().optional(),
  uid: z.string().optional(),
  name: z.string().optional(),
  projectId: z.string().optional(),
  environments: z.array(z.string()).optional(),
  triggers: z.boolean().optional(),
  events: z.array(z.string()).optional(),
  icon: z.string().optional(),
  backgroundColor: z.string().optional(),
  accentColor: z.string().optional(),
  data: smartUnion([
    z.lazy(() => TypeGithub$outboundSchema),
    z.lazy(() => TypeSlack$outboundSchema),
    z.lazy(() => TypeSalesforce$outboundSchema),
    z.lazy(() => TypeLinear$outboundSchema),
    z.lazy(() => TypeSnowflake$outboundSchema),
    z.lazy(() => TypeOauth$outboundSchema),
    z.lazy(() => TypeApiKey$outboundSchema),
    z.lazy(() => TypeSnowflakeWif$outboundSchema),
    z.record(z.any()),
  ]),
});

export function createConnectorRequestBodyToJSON(
  createConnectorRequestBody: CreateConnectorRequestBody,
): string {
  return JSON.stringify(
    CreateConnectorRequestBody$outboundSchema.parse(createConnectorRequestBody),
  );
}

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

/** @internal */
export const CreatedBy2$inboundSchema: z.ZodType<
  CreatedBy2,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("project"),
  id: types.string(),
  environment: CreatedByEnvironment$inboundSchema,
});

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

/** @internal */
export const CreatedBy1$inboundSchema: z.ZodType<
  CreatedBy1,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("user"),
  id: types.string(),
});

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

/** @internal */
export const CreatedBy$inboundSchema: z.ZodType<
  CreatedBy,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => CreatedBy1$inboundSchema),
  z.lazy(() => CreatedBy2$inboundSchema),
]);

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

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

/** @internal */
export const UpdatedBy2$inboundSchema: z.ZodType<
  UpdatedBy2,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("project"),
  id: types.string(),
  environment: UpdatedByEnvironment$inboundSchema,
});

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

/** @internal */
export const UpdatedBy1$inboundSchema: z.ZodType<
  UpdatedBy1,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("user"),
  id: types.string(),
});

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

/** @internal */
export const UpdatedBy$inboundSchema: z.ZodType<
  UpdatedBy,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => UpdatedBy1$inboundSchema),
  z.lazy(() => UpdatedBy2$inboundSchema),
]);

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

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

/** @internal */
export const AppTokens$inboundSchema: z.ZodType<
  AppTokens,
  z.ZodTypeDef,
  unknown
> = z.object({
  crossInstallation: types.boolean(),
  supportsRefinement: types.boolean(),
  requiresReinstallation: types.optional(types.boolean()),
  scopes: types.optional(z.array(types.string())),
  supportedAuthorizationDetails: types.optional(z.array(types.string())),
});

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

/** @internal */
export const UserTokens$inboundSchema: z.ZodType<
  UserTokens,
  z.ZodTypeDef,
  unknown
> = z.object({
  crossInstallation: types.boolean(),
  supportsRefinement: types.boolean(),
  scopes: types.optional(z.array(types.string())),
  supportedAuthorizationDetails: types.optional(z.array(types.string())),
});

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

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

/** @internal */
export const Triggers$inboundSchema: z.ZodType<
  Triggers,
  z.ZodTypeDef,
  unknown
> = z.object({
  enabled: types.boolean(),
});

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

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

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

/** @internal */
export const CreateConnectorProject$inboundSchema: z.ZodType<
  CreateConnectorProject,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  name: types.string(),
});

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

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

/** @internal */
export const CreateConnectorItems$inboundSchema: z.ZodType<
  CreateConnectorItems,
  z.ZodTypeDef,
  unknown
> = z.object({
  clientId: types.string(),
  projectId: types.string(),
  project: types.optional(z.lazy(() => CreateConnectorProject$inboundSchema)),
  environments: z.array(CreateConnectorEnvironments$inboundSchema),
  createdAt: types.number(),
  updatedAt: types.number(),
});

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

/** @internal */
export const CreateConnectorProjects$inboundSchema: z.ZodType<
  CreateConnectorProjects,
  z.ZodTypeDef,
  unknown
> = z.object({
  items: z.array(z.lazy(() => CreateConnectorItems$inboundSchema)),
  hasMore: types.boolean(),
  cursor: z.nullable(types.string()).optional(),
});

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

/** @internal */
export const Includes$inboundSchema: z.ZodType<
  Includes,
  z.ZodTypeDef,
  unknown
> = z.object({
  projects: types.optional(z.lazy(() => CreateConnectorProjects$inboundSchema)),
});

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

/** @internal */
export const CreateConnectorResponseBody$inboundSchema: z.ZodType<
  CreateConnectorResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  ownerId: types.string(),
  createdAt: types.number(),
  updatedAt: types.number(),
  deletedAt: types.optional(types.number()),
  createdBy: types.optional(
    z.union([
      z.lazy(() => CreatedBy1$inboundSchema),
      z.lazy(() => CreatedBy2$inboundSchema),
    ]),
  ),
  updatedBy: types.optional(
    z.union([
      z.lazy(() => UpdatedBy1$inboundSchema),
      z.lazy(() => UpdatedBy2$inboundSchema),
    ]),
  ),
  public: types.boolean(),
  uid: types.string(),
  type: CreateConnectorType$inboundSchema,
  service: types.string(),
  name: types.string(),
  clientUrl: z.nullable(types.string()).optional(),
  redirectUri: types.optional(types.string()),
  defaultInstallationId: types.optional(types.string()),
  data: z.record(z.any()),
  typeName: types.string(),
  typeIcon: types.optional(types.string()),
  website: types.optional(types.string()),
  devsite: types.optional(types.string()),
  docsite: types.optional(types.string()),
  icon: types.optional(types.string()),
  backgroundColor: types.optional(types.string()),
  accentColor: types.optional(types.string()),
  supportedSubjectTypes: z.array(types.string()),
  appTokens: types.optional(z.lazy(() => AppTokens$inboundSchema)),
  userTokens: types.optional(z.lazy(() => UserTokens$inboundSchema)),
  supportsInstallation: types.boolean(),
  supportsRevocation: types.boolean(),
  ownerTenantId: types.optional(types.string()),
  supportsTriggers: types.boolean(),
  supportsIcon: SupportsIcon$inboundSchema,
  triggers: types.optional(z.lazy(() => Triggers$inboundSchema)),
  events: types.optional(z.array(types.string())),
  triggerDestinations: types.optional(
    z.array(z.lazy(() => TriggerDestinations$inboundSchema)),
  ),
  includes: types.optional(z.lazy(() => Includes$inboundSchema)),
});

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