/*
 * 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 { smartUnion } from "../types/smartUnion.js";
import { NamedSandbox, NamedSandbox$inboundSchema } from "./namedsandbox.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
import { Session, Session$inboundSchema } from "./session.js";
import { Snapshot, Snapshot$inboundSchema } from "./snapshot.js";

export type StopSessionRequest = {
  /**
   * The unique identifier of the session to stop.
   */
  sessionId: 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 type StopSessionResponseBody2 = {
  /**
   * This object contains information related to a Snapshot of a Vercel Sandbox session (v2 API).
   */
  snapshot: Snapshot;
  /**
   * This object contains information related to a Vercel NamedSandbox.
   */
  sandbox: NamedSandbox;
  /**
   * This object contains information related to a Vercel Sandbox Session. v2 endpoints return "session" instead of "sandbox" as the response wrapper key.
   */
  session: Session;
};

export type StopSessionResponseBody1 = {
  /**
   * This object contains information related to a Vercel Sandbox Session. v2 endpoints return "session" instead of "sandbox" as the response wrapper key.
   */
  session: Session;
};

/**
 * The session was stopped successfully.
 */
export type StopSessionResponseBody =
  | StopSessionResponseBody2
  | StopSessionResponseBody1;

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

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

export function stopSessionRequestToJSON(
  stopSessionRequest: StopSessionRequest,
): string {
  return JSON.stringify(
    StopSessionRequest$outboundSchema.parse(stopSessionRequest),
  );
}

/** @internal */
export const StopSessionResponseBody2$inboundSchema: z.ZodType<
  StopSessionResponseBody2,
  z.ZodTypeDef,
  unknown
> = z.object({
  snapshot: Snapshot$inboundSchema,
  sandbox: NamedSandbox$inboundSchema,
  session: Session$inboundSchema,
});

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

/** @internal */
export const StopSessionResponseBody1$inboundSchema: z.ZodType<
  StopSessionResponseBody1,
  z.ZodTypeDef,
  unknown
> = z.object({
  session: Session$inboundSchema,
});

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

/** @internal */
export const StopSessionResponseBody$inboundSchema: z.ZodType<
  StopSessionResponseBody,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => StopSessionResponseBody2$inboundSchema),
  z.lazy(() => StopSessionResponseBody1$inboundSchema),
]);

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