/*
 * 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 GetTokenDetailsServerList = [
  "https://plex.tv/api/v2",
] as const;

export type GetTokenDetailsGlobals = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * The name of the client product
   */
  product?: string | undefined;
  /**
   * The version of the client application
   */
  version?: string | undefined;
  /**
   * The platform of the client
   */
  platform?: string | undefined;
  /**
   * The version of the platform
   */
  platformVersion?: string | undefined;
  /**
   * A relatively friendly name for the client device
   */
  device?: string | undefined;
  /**
   * A potentially less friendly identifier for the device model
   */
  model?: string | undefined;
  /**
   * The device vendor
   */
  deviceVendor?: string | undefined;
  /**
   * A friendly name for the client
   */
  deviceName?: string | undefined;
  /**
   * The marketplace on which the client application is distributed
   */
  marketplace?: string | undefined;
};

export type GetTokenDetailsRequest = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * The name of the client product
   */
  product?: string | undefined;
  /**
   * The version of the client application
   */
  version?: string | undefined;
  /**
   * The platform of the client
   */
  platform?: string | undefined;
  /**
   * The version of the platform
   */
  platformVersion?: string | undefined;
  /**
   * A relatively friendly name for the client device
   */
  device?: string | undefined;
  /**
   * A potentially less friendly identifier for the device model
   */
  model?: string | undefined;
  /**
   * The device vendor
   */
  deviceVendor?: string | undefined;
  /**
   * A friendly name for the client
   */
  deviceName?: string | undefined;
  /**
   * The marketplace on which the client application is distributed
   */
  marketplace?: string | undefined;
};

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

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

export type GetTokenDetailsResponse = {
  /**
   * 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;
  /**
   * Logged in user details
   */
  userPlexAccount?: shared.UserPlexAccount | undefined;
};

/** @internal */
export type GetTokenDetailsRequest$Outbound = {
  accepts: string;
  "Client-Identifier"?: string | undefined;
  Product?: string | undefined;
  Version?: string | undefined;
  Platform?: string | undefined;
  "Platform-Version"?: string | undefined;
  Device?: string | undefined;
  Model?: string | undefined;
  "Device-Vendor"?: string | undefined;
  "Device-Name"?: string | undefined;
  Marketplace?: string | undefined;
};

/** @internal */
export const GetTokenDetailsRequest$outboundSchema: z.ZodType<
  GetTokenDetailsRequest$Outbound,
  z.ZodTypeDef,
  GetTokenDetailsRequest
> = z.object({
  accepts: shared.Accepts$outboundSchema.default(shared.Accepts.ApplicationXml),
  clientIdentifier: z.string().optional(),
  product: z.string().optional(),
  version: z.string().optional(),
  platform: z.string().optional(),
  platformVersion: z.string().optional(),
  device: z.string().optional(),
  model: z.string().optional(),
  deviceVendor: z.string().optional(),
  deviceName: z.string().optional(),
  marketplace: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    clientIdentifier: "Client-Identifier",
    product: "Product",
    version: "Version",
    platform: "Platform",
    platformVersion: "Platform-Version",
    device: "Device",
    model: "Model",
    deviceVendor: "Device-Vendor",
    deviceName: "Device-Name",
    marketplace: "Marketplace",
  });
});

export function getTokenDetailsRequestToJSON(
  getTokenDetailsRequest: GetTokenDetailsRequest,
): string {
  return JSON.stringify(
    GetTokenDetailsRequest$outboundSchema.parse(getTokenDetailsRequest),
  );
}

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

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

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

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

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

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