/*
 * 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 ReportGlobals = {
  /**
   * 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 current state of the media.
 */
export enum ReportState {
  Stopped = "stopped",
  Buffering = "buffering",
  Playing = "playing",
  Paused = "paused",
}

export type ReportRequest = {
  /**
   * 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 details key for the item.
   */
  key?: string | undefined;
  /**
   * The rating key attribute for the item.
   */
  ratingKey?: string | undefined;
  /**
   * The current state of the media.
   */
  state?: ReportState | undefined;
  /**
   * If playing media from a play queue, the play queue's ID.
   */
  playQueueItemID?: string | undefined;
  /**
   * The current time offset of playback in ms.
   */
  time?: number | undefined;
  /**
   * The total duration of the item in ms.
   */
  duration?: number | undefined;
  /**
   * When state is `stopped`, a flag indicating whether or not the client is going to continue playing anothe item.
   */
  continuing?: shared.BoolInt | undefined;
  /**
   * Used when a sync client comes online and is syncing media timelines, holds the time at which the playback state was last updated.
   */
  updated?: number | undefined;
  /**
   * Also used by sync clients, used to indicate that a timeline is being synced from being offline, as opposed to being "live".
   */
  offline?: shared.BoolInt | undefined;
  /**
   * Time in seconds till first frame is displayed.  Sent only on the first playing timeline request.
   */
  timeToFirstFrame?: number | undefined;
  /**
   * Time in seconds spent buffering since last request.
   */
  timeStalled?: number | undefined;
  /**
   * Bandwidth in kbps as estimated by the client.
   */
  bandwidth?: number | undefined;
  /**
   * Amount of time in seconds buffered by client.  Omit if computed by `bufferedSize` below.
   */
  bufferedTime?: number | undefined;
  /**
   * Size in kilobytes of data buffered by client.  Omit if computed by `bufferedTime` above
   */
  bufferedSize?: number | undefined;
  /**
   * Unique per client playback session.  Used if a client can playback multiple items at a time (such as a browser with multiple tabs)
   */
  xPlexSessionIdentifier?: string | undefined;
};

export type Bandwidth = {
  /**
   * The bandwidth at this time in kbps
   */
  bandwidth?: number | undefined;
  /**
   * The user-friendly resolution at this time
   */
  resolution?: string | undefined;
  /**
   * Media playback time where this bandwidth started
   */
  time?: number | undefined;
};

/**
 * A list of media times and bandwidths when trascoding is using with auto adjustment of bandwidth
 */
export type Bandwidths = {
  bandwidth?: Array<Bandwidth> | 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 ReportMediaContainer = {
  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;
  allowCameraUpload?: boolean | undefined;
  allowChannelAccess?: boolean | undefined;
  allowMediaDeletion?: boolean | undefined;
  allowSharing?: boolean | undefined;
  allowSync?: boolean | undefined;
  allowTuners?: boolean | undefined;
  backgroundProcessing?: boolean | undefined;
  certificate?: boolean | undefined;
  companionProxy?: boolean | undefined;
  countryCode?: string | undefined;
  diagnostics?: string | undefined;
  eventStream?: boolean | undefined;
  friendlyName?: string | undefined;
  hubSearch?: boolean | undefined;
  itemClusters?: boolean | undefined;
  livetv?: number | undefined;
  machineIdentifier?: any | undefined;
  mediaProviders?: boolean | undefined;
  multiuser?: boolean | undefined;
  musicAnalysis?: number | undefined;
  myPlex?: boolean | undefined;
  myPlexMappingState?: any | undefined;
  myPlexSigninState?: any | undefined;
  myPlexSubscription?: boolean | undefined;
  myPlexUsername?: string | undefined;
  offlineTranscode?: any | undefined;
  /**
   * A comma-separated list of features which are enabled for the server owner
   */
  ownerFeatures?: string | undefined;
  platform?: string | undefined;
  platformVersion?: string | undefined;
  pluginHost?: boolean | undefined;
  pushNotifications?: boolean | undefined;
  readOnlyLibraries?: boolean | undefined;
  streamingBrainABRVersion?: number | undefined;
  streamingBrainVersion?: number | undefined;
  sync?: boolean | undefined;
  transcoderActiveVideoSessions?: number | undefined;
  transcoderAudio?: boolean | undefined;
  transcoderLyrics?: boolean | undefined;
  transcoderPhoto?: boolean | undefined;
  transcoderSubtitles?: boolean | undefined;
  transcoderVideo?: boolean | undefined;
  /**
   * The suggested video quality bitrates to present to the user
   */
  transcoderVideoBitrates?: any | undefined;
  transcoderVideoQualities?: string | undefined;
  /**
   * The suggested video resolutions to the above quality bitrates
   */
  transcoderVideoResolutions?: any | undefined;
  updatedAt?: number | undefined;
  updater?: boolean | undefined;
  version?: string | undefined;
  voiceSearch?: boolean | undefined;
  /**
   * A list of media times and bandwidths when trascoding is using with auto adjustment of bandwidth
   */
  bandwidths?: Bandwidths | undefined;
  /**
   * A code describing why the session was terminated by the server.
   */
  terminationCode?: number | undefined;
  /**
   * A user friendly and localized text describing why the session was terminated by the server.
   */
  terminationText?: string | undefined;
};

/**
 * OK
 */
export type ReportResponseBody = {
  mediaContainer?: ReportMediaContainer | undefined;
};

export type ReportResponse = {
  /**
   * 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?: ReportResponseBody | undefined;
};

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

/** @internal */
export type ReportRequest$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;
  key?: string | undefined;
  ratingKey?: string | undefined;
  state?: string | undefined;
  playQueueItemID?: string | undefined;
  time?: number | undefined;
  duration?: number | undefined;
  continuing: number;
  updated?: number | undefined;
  offline: number;
  timeToFirstFrame?: number | undefined;
  timeStalled?: number | undefined;
  bandwidth?: number | undefined;
  bufferedTime?: number | undefined;
  bufferedSize?: number | undefined;
  "X-Plex-Session-Identifier"?: string | undefined;
};

/** @internal */
export const ReportRequest$outboundSchema: z.ZodType<
  ReportRequest$Outbound,
  z.ZodTypeDef,
  ReportRequest
> = 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(),
  key: z.string().optional(),
  ratingKey: z.string().optional(),
  state: ReportState$outboundSchema.optional(),
  playQueueItemID: z.string().optional(),
  time: z.number().int().optional(),
  duration: z.number().int().optional(),
  continuing: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  updated: z.number().int().optional(),
  offline: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  timeToFirstFrame: z.number().int().optional(),
  timeStalled: z.number().int().optional(),
  bandwidth: z.number().int().optional(),
  bufferedTime: z.number().int().optional(),
  bufferedSize: z.number().int().optional(),
  xPlexSessionIdentifier: 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",
    xPlexSessionIdentifier: "X-Plex-Session-Identifier",
  });
});

export function reportRequestToJSON(reportRequest: ReportRequest): string {
  return JSON.stringify(ReportRequest$outboundSchema.parse(reportRequest));
}

/** @internal */
export const Bandwidth$inboundSchema: z.ZodType<
  Bandwidth,
  z.ZodTypeDef,
  unknown
> = z.object({
  bandwidth: z.number().int().optional(),
  resolution: z.string().optional(),
  time: z.number().int().optional(),
});

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

/** @internal */
export const Bandwidths$inboundSchema: z.ZodType<
  Bandwidths,
  z.ZodTypeDef,
  unknown
> = z.object({
  Bandwidth: z.array(z.lazy(() => Bandwidth$inboundSchema)).optional(),
}).transform((v) => {
  return remap$(v, {
    "Bandwidth": "bandwidth",
  });
});

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

/** @internal */
export const ReportMediaContainer$inboundSchema: z.ZodType<
  ReportMediaContainer,
  z.ZodTypeDef,
  unknown
> = z.object({
  identifier: z.string().optional(),
  offset: z.number().int().optional(),
  size: z.number().int().optional(),
  totalSize: z.number().int().optional(),
  allowCameraUpload: z.boolean().optional(),
  allowChannelAccess: z.boolean().optional(),
  allowMediaDeletion: z.boolean().optional(),
  allowSharing: z.boolean().optional(),
  allowSync: z.boolean().optional(),
  allowTuners: z.boolean().optional(),
  backgroundProcessing: z.boolean().optional(),
  certificate: z.boolean().optional(),
  companionProxy: z.boolean().optional(),
  countryCode: z.string().optional(),
  diagnostics: z.string().optional(),
  eventStream: z.boolean().optional(),
  friendlyName: z.string().optional(),
  hubSearch: z.boolean().optional(),
  itemClusters: z.boolean().optional(),
  livetv: z.number().int().optional(),
  machineIdentifier: z.any().optional(),
  mediaProviders: z.boolean().optional(),
  multiuser: z.boolean().optional(),
  musicAnalysis: z.number().int().optional(),
  myPlex: z.boolean().optional(),
  myPlexMappingState: z.any().optional(),
  myPlexSigninState: z.any().optional(),
  myPlexSubscription: z.boolean().optional(),
  myPlexUsername: z.string().optional(),
  offlineTranscode: z.any().optional(),
  ownerFeatures: z.string().optional(),
  platform: z.string().optional(),
  platformVersion: z.string().optional(),
  pluginHost: z.boolean().optional(),
  pushNotifications: z.boolean().optional(),
  readOnlyLibraries: z.boolean().optional(),
  streamingBrainABRVersion: z.number().int().optional(),
  streamingBrainVersion: z.number().int().optional(),
  sync: z.boolean().optional(),
  transcoderActiveVideoSessions: z.number().int().optional(),
  transcoderAudio: z.boolean().optional(),
  transcoderLyrics: z.boolean().optional(),
  transcoderPhoto: z.boolean().optional(),
  transcoderSubtitles: z.boolean().optional(),
  transcoderVideo: z.boolean().optional(),
  transcoderVideoBitrates: z.any().optional(),
  transcoderVideoQualities: z.string().optional(),
  transcoderVideoResolutions: z.any().optional(),
  updatedAt: z.number().int().optional(),
  updater: z.boolean().optional(),
  version: z.string().optional(),
  voiceSearch: z.boolean().optional(),
  Bandwidths: z.lazy(() => Bandwidths$inboundSchema).optional(),
  terminationCode: z.number().int().optional(),
  terminationText: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    "Bandwidths": "bandwidths",
  });
});

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

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

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

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

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