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

export type RemoveCustomEnvironmentRequestBody = {
  /**
   * Delete Environment Variables that are not assigned to any environments.
   */
  deleteUnassignedEnvironmentVariables?: boolean | undefined;
};

export type RemoveCustomEnvironmentRequest = {
  /**
   * The unique project identifier or the project name
   */
  idOrName: string;
  /**
   * The unique custom environment identifier within the project
   */
  environmentSlugOrId: 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;
  requestBody?: RemoveCustomEnvironmentRequestBody | undefined;
};

/**
 * The type of environment (production, preview, or development)
 */
export const RemoveCustomEnvironmentType = {
  Development: "development",
  Preview: "preview",
  Production: "production",
} as const;
/**
 * The type of environment (production, preview, or development)
 */
export type RemoveCustomEnvironmentType = ClosedEnum<
  typeof RemoveCustomEnvironmentType
>;

/**
 * The type of matching to perform
 */
export const RemoveCustomEnvironmentEnvironmentType = {
  EndsWith: "endsWith",
  Equals: "equals",
  StartsWith: "startsWith",
} as const;
/**
 * The type of matching to perform
 */
export type RemoveCustomEnvironmentEnvironmentType = ClosedEnum<
  typeof RemoveCustomEnvironmentEnvironmentType
>;

/**
 * Configuration for matching git branches to this environment
 */
export type RemoveCustomEnvironmentBranchMatcher = {
  /**
   * The type of matching to perform
   */
  type: RemoveCustomEnvironmentEnvironmentType;
  /**
   * The pattern to match against branch names
   */
  pattern: string;
};

/**
 * A list of verification challenges, one of which must be completed to verify the domain for use on the project. After the challenge is complete `POST /projects/:idOrName/domains/:domain/verify` to verify the domain. Possible challenges: - If `verification.type = TXT` the `verification.domain` will be checked for a TXT record matching `verification.value`.
 */
export type RemoveCustomEnvironmentVerification = {
  type: string;
  domain: string;
  value: string;
  reason: string;
};

/**
 * List of domains associated with this environment
 */
export type RemoveCustomEnvironmentDomains = {
  name: string;
  apexName: string;
  projectId: string;
  redirect?: string | null | undefined;
  redirectStatusCode?: number | null | undefined;
  gitBranch?: string | null | undefined;
  customEnvironmentId?: string | null | undefined;
  updatedAt?: number | undefined;
  createdAt?: number | undefined;
  /**
   * `true` if the domain is verified for use with the project. If `false` it will not be used as an alias on this project until the challenge in `verification` is completed.
   */
  verified: boolean;
  /**
   * A list of verification challenges, one of which must be completed to verify the domain for use on the project. After the challenge is complete `POST /projects/:idOrName/domains/:domain/verify` to verify the domain. Possible challenges: - If `verification.type = TXT` the `verification.domain` will be checked for a TXT record matching `verification.value`.
   */
  verification?: Array<RemoveCustomEnvironmentVerification> | undefined;
};

/**
 * Internal representation of a custom environment with all required properties
 */
export type RemoveCustomEnvironmentResponseBody = {
  /**
   * Unique identifier for the custom environment (format: env_*)
   */
  id: string;
  /**
   * URL-friendly name of the environment
   */
  slug: string;
  /**
   * The type of environment (production, preview, or development)
   */
  type: RemoveCustomEnvironmentType;
  /**
   * Optional description of the environment's purpose
   */
  description?: string | undefined;
  /**
   * Configuration for matching git branches to this environment
   */
  branchMatcher?: RemoveCustomEnvironmentBranchMatcher | undefined;
  /**
   * List of domains associated with this environment
   */
  domains?: Array<RemoveCustomEnvironmentDomains> | undefined;
  /**
   * List of aliases for the current deployment
   */
  currentDeploymentAliases?: Array<string> | undefined;
  /**
   * Timestamp when the environment was created
   */
  createdAt: number;
  /**
   * Timestamp when the environment was last updated
   */
  updatedAt: number;
};

/** @internal */
export type RemoveCustomEnvironmentRequestBody$Outbound = {
  deleteUnassignedEnvironmentVariables?: boolean | undefined;
};

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

export function removeCustomEnvironmentRequestBodyToJSON(
  removeCustomEnvironmentRequestBody: RemoveCustomEnvironmentRequestBody,
): string {
  return JSON.stringify(
    RemoveCustomEnvironmentRequestBody$outboundSchema.parse(
      removeCustomEnvironmentRequestBody,
    ),
  );
}

/** @internal */
export type RemoveCustomEnvironmentRequest$Outbound = {
  idOrName: string;
  environmentSlugOrId: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?: RemoveCustomEnvironmentRequestBody$Outbound | undefined;
};

/** @internal */
export const RemoveCustomEnvironmentRequest$outboundSchema: z.ZodType<
  RemoveCustomEnvironmentRequest$Outbound,
  z.ZodTypeDef,
  RemoveCustomEnvironmentRequest
> = z.object({
  idOrName: z.string(),
  environmentSlugOrId: z.string(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: z.lazy(() => RemoveCustomEnvironmentRequestBody$outboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function removeCustomEnvironmentRequestToJSON(
  removeCustomEnvironmentRequest: RemoveCustomEnvironmentRequest,
): string {
  return JSON.stringify(
    RemoveCustomEnvironmentRequest$outboundSchema.parse(
      removeCustomEnvironmentRequest,
    ),
  );
}

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

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

/** @internal */
export const RemoveCustomEnvironmentBranchMatcher$inboundSchema: z.ZodType<
  RemoveCustomEnvironmentBranchMatcher,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: RemoveCustomEnvironmentEnvironmentType$inboundSchema,
  pattern: types.string(),
});

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

/** @internal */
export const RemoveCustomEnvironmentVerification$inboundSchema: z.ZodType<
  RemoveCustomEnvironmentVerification,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.string(),
  domain: types.string(),
  value: types.string(),
  reason: types.string(),
});

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

/** @internal */
export const RemoveCustomEnvironmentDomains$inboundSchema: z.ZodType<
  RemoveCustomEnvironmentDomains,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: types.string(),
  apexName: types.string(),
  projectId: types.string(),
  redirect: z.nullable(types.string()).optional(),
  redirectStatusCode: z.nullable(types.number()).optional(),
  gitBranch: z.nullable(types.string()).optional(),
  customEnvironmentId: z.nullable(types.string()).optional(),
  updatedAt: types.optional(types.number()),
  createdAt: types.optional(types.number()),
  verified: types.boolean(),
  verification: types.optional(
    z.array(z.lazy(() => RemoveCustomEnvironmentVerification$inboundSchema)),
  ),
});

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

/** @internal */
export const RemoveCustomEnvironmentResponseBody$inboundSchema: z.ZodType<
  RemoveCustomEnvironmentResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  slug: types.string(),
  type: RemoveCustomEnvironmentType$inboundSchema,
  description: types.optional(types.string()),
  branchMatcher: types.optional(
    z.lazy(() => RemoveCustomEnvironmentBranchMatcher$inboundSchema),
  ),
  domains: types.optional(
    z.array(z.lazy(() => RemoveCustomEnvironmentDomains$inboundSchema)),
  ),
  currentDeploymentAliases: types.optional(z.array(types.string())),
  createdAt: types.number(),
  updatedAt: types.number(),
});

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