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

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

export type GetRollingReleaseConfigRequest = {
  /**
   * Project ID or project name (URL-encoded)
   */
  idOrName: 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;
};

/**
 * An array of all the stages required during a deployment release. Each stage defines a target percentage and advancement rules. The final stage must always have targetPercentage: 100.
 */
export type GetRollingReleaseConfigStages = {
  /**
   * The percentage of traffic to serve to the canary deployment (0-100)
   */
  targetPercentage: number;
  /**
   * Whether or not this stage requires manual approval to proceed
   */
  requireApproval?: boolean | undefined;
  /**
   * Duration in minutes for automatic advancement to the next stage
   */
  duration?: number | undefined;
  /**
   * Whether to linearly shift traffic over the duration of this stage
   */
  linearShift?: boolean | undefined;
};

/**
 * Project-level rolling release configuration that defines how deployments should be gradually rolled out
 */
export type GetRollingReleaseConfigRollingRelease = {
  /**
   * The environment that the release targets, currently only supports production. Adding in case we want to configure with alias groups or custom environments.
   */
  target: string;
  /**
   * An array of all the stages required during a deployment release. Each stage defines a target percentage and advancement rules. The final stage must always have targetPercentage: 100.
   */
  stages?: Array<GetRollingReleaseConfigStages> | null | undefined;
  /**
   * Whether the request served by a canary deployment should return a header indicating a canary was served. Defaults to `false` when omitted.
   */
  canaryResponseHeader?: boolean | undefined;
};

export type GetRollingReleaseConfigResponseBody = {
  /**
   * Project-level rolling release configuration that defines how deployments should be gradually rolled out
   */
  rollingRelease: GetRollingReleaseConfigRollingRelease | null;
};

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

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

export function getRollingReleaseConfigRequestToJSON(
  getRollingReleaseConfigRequest: GetRollingReleaseConfigRequest,
): string {
  return JSON.stringify(
    GetRollingReleaseConfigRequest$outboundSchema.parse(
      getRollingReleaseConfigRequest,
    ),
  );
}

/** @internal */
export const GetRollingReleaseConfigStages$inboundSchema: z.ZodType<
  GetRollingReleaseConfigStages,
  z.ZodTypeDef,
  unknown
> = z.object({
  targetPercentage: types.number(),
  requireApproval: types.optional(types.boolean()),
  duration: types.optional(types.number()),
  linearShift: types.optional(types.boolean()),
});

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

/** @internal */
export const GetRollingReleaseConfigRollingRelease$inboundSchema: z.ZodType<
  GetRollingReleaseConfigRollingRelease,
  z.ZodTypeDef,
  unknown
> = z.object({
  target: types.string(),
  stages: z.nullable(
    z.array(z.lazy(() => GetRollingReleaseConfigStages$inboundSchema)),
  ).optional(),
  canaryResponseHeader: types.optional(types.boolean()),
});

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

/** @internal */
export const GetRollingReleaseConfigResponseBody$inboundSchema: z.ZodType<
  GetRollingReleaseConfigResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  rollingRelease: types.nullable(
    z.lazy(() => GetRollingReleaseConfigRollingRelease$inboundSchema),
  ),
});

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