/*
 * 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 AssignAliasRequestBody = {
  /**
   * The alias we want to assign to the deployment defined in the URL
   */
  alias?: string | undefined;
  /**
   * The redirect property will take precedence over the deployment id from the URL and consists of a hostname (like test.com) to which the alias should redirect using status code 307
   */
  redirect?: string | null | undefined;
};

export type AssignAliasRequest = {
  /**
   * The deployment or alias ID or URL to assign from
   */
  id: 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: AssignAliasRequestBody;
};

/**
 * The alias was successfully assigned to the deployment
 */
export type AssignAliasResponseBody = {
  /**
   * The unique identifier of the alias
   */
  uid: string;
  /**
   * The assigned alias name
   */
  alias: string;
  /**
   * The date when the alias was created
   */
  created: Date;
  /**
   * The unique identifier of the previously aliased deployment, only received when the alias was used before
   */
  oldDeploymentId?: string | null | undefined;
};

/** @internal */
export type AssignAliasRequestBody$Outbound = {
  alias?: string | undefined;
  redirect?: string | null | undefined;
};

/** @internal */
export const AssignAliasRequestBody$outboundSchema: z.ZodType<
  AssignAliasRequestBody$Outbound,
  z.ZodTypeDef,
  AssignAliasRequestBody
> = z.object({
  alias: z.string().optional(),
  redirect: z.nullable(z.string()).optional(),
});

export function assignAliasRequestBodyToJSON(
  assignAliasRequestBody: AssignAliasRequestBody,
): string {
  return JSON.stringify(
    AssignAliasRequestBody$outboundSchema.parse(assignAliasRequestBody),
  );
}

/** @internal */
export type AssignAliasRequest$Outbound = {
  id: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody: AssignAliasRequestBody$Outbound;
};

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

export function assignAliasRequestToJSON(
  assignAliasRequest: AssignAliasRequest,
): string {
  return JSON.stringify(
    AssignAliasRequest$outboundSchema.parse(assignAliasRequest),
  );
}

/** @internal */
export const AssignAliasResponseBody$inboundSchema: z.ZodType<
  AssignAliasResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  uid: types.string(),
  alias: types.string(),
  created: types.date(),
  oldDeploymentId: z.nullable(types.string()).optional(),
});

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