/*
 * 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 * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type GetProjectCheckRequest = {
  projectIdOrName: string;
  /**
   * The ID of the resource that will be updated.
   */
  checkId: string;
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
};

export const GetProjectCheckRequires = {
  BuildReady: "build-ready",
  DeploymentUrl: "deployment-url",
  None: "none",
} as const;
export type GetProjectCheckRequires = ClosedEnum<
  typeof GetProjectCheckRequires
>;

export const GetProjectCheckSourceProvider = {
  Bitbucket: "bitbucket",
  Github: "github",
  Gitlab: "gitlab",
} as const;
export type GetProjectCheckSourceProvider = ClosedEnum<
  typeof GetProjectCheckSourceProvider
>;

export type GetProjectCheckSource3 = {
  kind: "git-provider";
  provider: GetProjectCheckSourceProvider;
  externalCheckName: string;
};

export type GetProjectCheckSource2 = {
  kind: "webhook";
  webhookId?: string | undefined;
};

export type GetProjectCheckSource1 = {
  kind: "integration";
  integrationId: string;
  integrationConfigurationId: string;
  resourceId?: string | undefined;
  externalResourceId?: string | undefined;
};

export type GetProjectCheckSource =
  | GetProjectCheckSource1
  | GetProjectCheckSource2
  | GetProjectCheckSource3;

export const GetProjectCheckBlocks = {
  BuildStart: "build-start",
  DeploymentAlias: "deployment-alias",
  DeploymentPromotion: "deployment-promotion",
  DeploymentStart: "deployment-start",
  None: "none",
} as const;
export type GetProjectCheckBlocks = ClosedEnum<typeof GetProjectCheckBlocks>;

export const GetProjectCheckSourceKind = {
  GitProvider: "git-provider",
  Integration: "integration",
  Vercel: "vercel",
  Webhook: "webhook",
} as const;
export type GetProjectCheckSourceKind = ClosedEnum<
  typeof GetProjectCheckSourceKind
>;

export type GetProjectCheckResponseBody = {
  id: string;
  name: string;
  ownerId: string;
  projectId: string;
  isRerequestable: boolean;
  requires: GetProjectCheckRequires;
  source:
    | GetProjectCheckSource1
    | GetProjectCheckSource2
    | GetProjectCheckSource3;
  blocks: GetProjectCheckBlocks;
  targets: Array<string>;
  sourceKind: GetProjectCheckSourceKind;
  sourceIntegrationConfigurationId?: string | undefined;
  timeout: number;
  createdAt: number;
  updatedAt: number;
  deletedAt?: number | undefined;
};

/** @internal */
export type GetProjectCheckRequest$Outbound = {
  projectIdOrName: string;
  checkId: string;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const GetProjectCheckRequest$outboundSchema: z.ZodType<
  GetProjectCheckRequest$Outbound,
  z.ZodTypeDef,
  GetProjectCheckRequest
> = z.object({
  projectIdOrName: z.string(),
  checkId: z.string(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function getProjectCheckRequestToJSON(
  getProjectCheckRequest: GetProjectCheckRequest,
): string {
  return JSON.stringify(
    GetProjectCheckRequest$outboundSchema.parse(getProjectCheckRequest),
  );
}

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

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

/** @internal */
export const GetProjectCheckSource3$inboundSchema: z.ZodType<
  GetProjectCheckSource3,
  z.ZodTypeDef,
  unknown
> = z.object({
  kind: types.literal("git-provider"),
  provider: GetProjectCheckSourceProvider$inboundSchema,
  externalCheckName: types.string(),
});

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

/** @internal */
export const GetProjectCheckSource2$inboundSchema: z.ZodType<
  GetProjectCheckSource2,
  z.ZodTypeDef,
  unknown
> = z.object({
  kind: types.literal("webhook"),
  webhookId: types.optional(types.string()),
});

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

/** @internal */
export const GetProjectCheckSource1$inboundSchema: z.ZodType<
  GetProjectCheckSource1,
  z.ZodTypeDef,
  unknown
> = z.object({
  kind: types.literal("integration"),
  integrationId: types.string(),
  integrationConfigurationId: types.string(),
  resourceId: types.optional(types.string()),
  externalResourceId: types.optional(types.string()),
});

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

/** @internal */
export const GetProjectCheckSource$inboundSchema: z.ZodType<
  GetProjectCheckSource,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => GetProjectCheckSource1$inboundSchema),
  z.lazy(() => GetProjectCheckSource2$inboundSchema),
  z.lazy(() => GetProjectCheckSource3$inboundSchema),
]);

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

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

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

/** @internal */
export const GetProjectCheckResponseBody$inboundSchema: z.ZodType<
  GetProjectCheckResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  name: types.string(),
  ownerId: types.string(),
  projectId: types.string(),
  isRerequestable: types.boolean(),
  requires: GetProjectCheckRequires$inboundSchema,
  source: z.union([
    z.lazy(() => GetProjectCheckSource1$inboundSchema),
    z.lazy(() => GetProjectCheckSource2$inboundSchema),
    z.lazy(() => GetProjectCheckSource3$inboundSchema),
  ]),
  blocks: GetProjectCheckBlocks$inboundSchema,
  targets: z.array(types.string()),
  sourceKind: GetProjectCheckSourceKind$inboundSchema,
  sourceIntegrationConfigurationId: types.optional(types.string()),
  timeout: types.number(),
  createdAt: types.number(),
  updatedAt: types.number(),
  deletedAt: types.optional(types.number()),
});

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