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

export type RestoreRedirectsRequestBody = {
  name?: string | undefined;
  /**
   * The redirects to restore. The source of the redirect is used to match the redirect to restore.
   */
  redirects: Array<string>;
};

export type RestoreRedirectsRequest = {
  projectId: 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?: RestoreRedirectsRequestBody | undefined;
};

export type RestoreRedirectsVersion = {
  /**
   * The unique identifier for the version.
   */
  id: string;
  /**
   * The key of the version. The key may be duplicated across versions if the contents are the same as a different version.
   */
  key: string;
  lastModified: number;
  createdBy: string;
  /**
   * Optional name for the version. If not provided, defaults to an ISO timestamp string.
   */
  name?: string | undefined;
  /**
   * Whether this version has not been promoted to production yet and is not serving end users.
   */
  isStaging?: boolean | undefined;
  /**
   * Whether this version is currently live in production.
   */
  isLive?: boolean | undefined;
  /**
   * The number of redirects in this version.
   */
  redirectCount?: number | undefined;
  /**
   * The staging link for previewing redirects in this version.
   */
  alias?: string | undefined;
};

export type RestoreRedirectsResponseBody = {
  version: RestoreRedirectsVersion;
  restored: Array<string>;
  failedToRestore: Array<string>;
};

/** @internal */
export type RestoreRedirectsRequestBody$Outbound = {
  name?: string | undefined;
  redirects: Array<string>;
};

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

export function restoreRedirectsRequestBodyToJSON(
  restoreRedirectsRequestBody: RestoreRedirectsRequestBody,
): string {
  return JSON.stringify(
    RestoreRedirectsRequestBody$outboundSchema.parse(
      restoreRedirectsRequestBody,
    ),
  );
}

/** @internal */
export type RestoreRedirectsRequest$Outbound = {
  projectId: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?: RestoreRedirectsRequestBody$Outbound | undefined;
};

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

export function restoreRedirectsRequestToJSON(
  restoreRedirectsRequest: RestoreRedirectsRequest,
): string {
  return JSON.stringify(
    RestoreRedirectsRequest$outboundSchema.parse(restoreRedirectsRequest),
  );
}

/** @internal */
export const RestoreRedirectsVersion$inboundSchema: z.ZodType<
  RestoreRedirectsVersion,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  key: types.string(),
  lastModified: types.number(),
  createdBy: types.string(),
  name: types.optional(types.string()),
  isStaging: types.optional(types.boolean()),
  isLive: types.optional(types.boolean()),
  redirectCount: types.optional(types.number()),
  alias: types.optional(types.string()),
});

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

/** @internal */
export const RestoreRedirectsResponseBody$inboundSchema: z.ZodType<
  RestoreRedirectsResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  version: z.lazy(() => RestoreRedirectsVersion$inboundSchema),
  restored: z.array(types.string()),
  failedToRestore: z.array(types.string()),
});

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