/*
 * 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 type GetSourceConnectionInformationGlobals = {
  /**
   * 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 GetSourceConnectionInformationRequest = {
  /**
   * 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;
  /**
   * The source identifier with an included prefix.
   */
  source: string;
  /**
   * Force refresh
   */
  refresh?: shared.BoolInt | undefined;
};

export type Connection = {
  address?: string | undefined;
  /**
   * Indicates if the connection is the server's LAN address
   */
  local?: boolean | undefined;
  port?: number | undefined;
  protocol?: string | undefined;
  /**
   * Indicates the connection is over a relayed connection
   */
  relay?: boolean | undefined;
  uri?: string | undefined;
};

export type GetSourceConnectionInformationDevice = {
  accessToken?: string | undefined;
  clientIdentifier?: string | undefined;
  connection?: Array<Connection> | undefined;
  name?: string | undefined;
};

/**
 * `MediaContainer` is the root element of most Plex API responses. It serves as a generic container for various types of content (Metadata, Hubs, Directories, etc.) and includes pagination information (offset, size, totalSize) when applicable.
 *
 * @remarks
 * Common attributes: - identifier: Unique identifier for this container - size: Number of items in this response page - totalSize: Total number of items available (for pagination) - offset: Starting index of this page (for pagination)
 * The container often "hoists" common attributes from its children. For example, if all tracks in a container share the same album title, the `parentTitle` attribute may appear on the MediaContainer rather than being repeated on each track.
 */
export type GetSourceConnectionInformationMediaContainer = {
  identifier?: string | undefined;
  /**
   * The offset of where this container page starts among the total objects available. Also provided in the `X-Plex-Container-Start` header.
   *
   * @remarks
   */
  offset?: number | undefined;
  size?: number | undefined;
  /**
   * The total size of objects available. Also provided in the `X-Plex-Container-Total-Size` header.
   *
   * @remarks
   */
  totalSize?: number | undefined;
  device?: GetSourceConnectionInformationDevice | undefined;
};

/**
 * OK
 */
export type GetSourceConnectionInformationResponseBody = {
  mediaContainer?: GetSourceConnectionInformationMediaContainer | undefined;
};

export type GetSourceConnectionInformationResponse = {
  /**
   * 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;
  /**
   * OK
   */
  object?: GetSourceConnectionInformationResponseBody | undefined;
};

/** @internal */
export type GetSourceConnectionInformationRequest$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;
  source: string;
  refresh: number;
};

/** @internal */
export const GetSourceConnectionInformationRequest$outboundSchema: z.ZodType<
  GetSourceConnectionInformationRequest$Outbound,
  z.ZodTypeDef,
  GetSourceConnectionInformationRequest
> = 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(),
  source: z.string(),
  refresh: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
}).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 getSourceConnectionInformationRequestToJSON(
  getSourceConnectionInformationRequest: GetSourceConnectionInformationRequest,
): string {
  return JSON.stringify(
    GetSourceConnectionInformationRequest$outboundSchema.parse(
      getSourceConnectionInformationRequest,
    ),
  );
}

/** @internal */
export const Connection$inboundSchema: z.ZodType<
  Connection,
  z.ZodTypeDef,
  unknown
> = z.object({
  address: z.string().optional(),
  local: z.boolean().optional(),
  port: z.number().int().optional(),
  protocol: z.string().optional(),
  relay: z.boolean().optional(),
  uri: z.string().optional(),
});

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

/** @internal */
export const GetSourceConnectionInformationDevice$inboundSchema: z.ZodType<
  GetSourceConnectionInformationDevice,
  z.ZodTypeDef,
  unknown
> = z.object({
  accessToken: z.string().optional(),
  clientIdentifier: z.string().optional(),
  Connection: z.array(z.lazy(() => Connection$inboundSchema)).optional(),
  name: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    "Connection": "connection",
  });
});

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

/** @internal */
export const GetSourceConnectionInformationMediaContainer$inboundSchema:
  z.ZodType<
    GetSourceConnectionInformationMediaContainer,
    z.ZodTypeDef,
    unknown
  > = z.object({
    identifier: z.string().optional(),
    offset: z.number().int().optional(),
    size: z.number().int().optional(),
    totalSize: z.number().int().optional(),
    Device: z.lazy(() => GetSourceConnectionInformationDevice$inboundSchema)
      .optional(),
  }).transform((v) => {
    return remap$(v, {
      "Device": "device",
    });
  });

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

/** @internal */
export const GetSourceConnectionInformationResponseBody$inboundSchema:
  z.ZodType<GetSourceConnectionInformationResponseBody, z.ZodTypeDef, unknown> =
    z.object({
      MediaContainer: z.lazy(() =>
        GetSourceConnectionInformationMediaContainer$inboundSchema
      ).optional(),
    }).transform((v) => {
      return remap$(v, {
        "MediaContainer": "mediaContainer",
      });
    });

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

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

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