/*
 * 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 { SDKValidationError } from "../errors/sdkvalidationerror.js";
import * as shared from "../shared/index.js";

export const GetServerResourcesServerList = [
  "https://plex.tv/api/v2",
] as const;

export type GetServerResourcesGlobals = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
};

/**
 * Include Https entries in the results
 */
export enum IncludeHttps {
  False = 0,
  True = 1,
}

/**
 * Include Relay addresses in the results
 *
 * @remarks
 * E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400
 */
export enum IncludeRelay {
  False = 0,
  True = 1,
}

/**
 * Include IPv6 entries in the results
 */
export enum IncludeIPv6 {
  False = 0,
  True = 1,
}

export type GetServerResourcesRequest = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * Include Https entries in the results
   */
  includeHttps?: IncludeHttps | undefined;
  /**
   * Include Relay addresses in the results
   *
   * @remarks
   * E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400
   */
  includeRelay?: IncludeRelay | undefined;
  /**
   * Include IPv6 entries in the results
   */
  includeIPv6?: IncludeIPv6 | undefined;
};

export type GetServerResourcesError = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

export type GetServerResourcesResponse = {
  /**
   * HTTP response content type for this operation
   */
  contentType: string;
  /**
   * HTTP response status code for this operation
   */
  statusCode: number;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse: Response;
  /**
   * List of Plex Devices. This includes Plex hosted servers and clients
   */
  plexDevices?: Array<shared.PlexDevice> | undefined;
};

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

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

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

/** @internal */
export type GetServerResourcesRequest$Outbound = {
  accepts: string;
  "Client-Identifier"?: string | undefined;
  includeHttps: number;
  includeRelay: number;
  includeIPv6: number;
};

/** @internal */
export const GetServerResourcesRequest$outboundSchema: z.ZodType<
  GetServerResourcesRequest$Outbound,
  z.ZodTypeDef,
  GetServerResourcesRequest
> = z.object({
  accepts: shared.Accepts$outboundSchema.default(shared.Accepts.ApplicationXml),
  clientIdentifier: z.string().optional(),
  includeHttps: IncludeHttps$outboundSchema.default(IncludeHttps.False),
  includeRelay: IncludeRelay$outboundSchema.default(IncludeRelay.False),
  includeIPv6: IncludeIPv6$outboundSchema.default(IncludeIPv6.False),
}).transform((v) => {
  return remap$(v, {
    clientIdentifier: "Client-Identifier",
  });
});

export function getServerResourcesRequestToJSON(
  getServerResourcesRequest: GetServerResourcesRequest,
): string {
  return JSON.stringify(
    GetServerResourcesRequest$outboundSchema.parse(getServerResourcesRequest),
  );
}

/** @internal */
export const GetServerResourcesError$inboundSchema: z.ZodType<
  GetServerResourcesError,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

/** @internal */
export const GetServerResourcesResponse$inboundSchema: z.ZodType<
  GetServerResourcesResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  PlexDevices: z.array(shared.PlexDevice$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
    "PlexDevices": "plexDevices",
  });
});

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