/*
 * 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 GetLibraryMatchesGlobals = {
  /**
   * 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 GetLibraryMatchesRequest = {
  /**
   * 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 type of media to retrieve or filter by.
   *
   * @remarks
   *
   * 1 = movie
   * 2 = show
   * 3 = season
   * 4 = episode
   * 5 = artist
   * 6 = album
   * 7 = track
   * 8 = photo_album
   * 9 = photo
   *
   * E.g. A movie library will not return anything with type 3 as there are no seasons for movie libraries
   */
  type?: shared.MediaType | undefined;
  includeFullMetadata?: shared.BoolInt | undefined;
  includeAncestorMetadata?: shared.BoolInt | undefined;
  includeAlternateMetadataSources?: shared.BoolInt | undefined;
  /**
   * Used for movies, shows, artists, albums, and tracks.  Allowed for various URI schemes, to be defined.
   */
  guid?: string | undefined;
  /**
   * The title to filter by or assign
   */
  title?: string | undefined;
  /**
   * Used for movies shows, and albums.  Optional.
   */
  year?: number | undefined;
  /**
   * Used for movies, episodes, and tracks.  The full path to the media file, used for "cloud-scanning" an item.
   */
  path?: string | undefined;
  /**
   * Used for episodes and tracks.  The title of the show/artist. Required if `path` isn't passed.
   */
  grandparentTitle?: string | undefined;
  /**
   * Used for episodes.  The year of the show.
   */
  grandparentYear?: number | undefined;
  /**
   * Used for episodes and tracks.  The season/album number.
   */
  parentIndex?: number | undefined;
  /**
   * Used for episodes and tracks.  The episode/tracks number in the season/album.
   */
  index?: number | undefined;
  /**
   * Used for episodes.  In the format `YYYY-MM-DD`.
   */
  originallyAvailableAt?: string | undefined;
  /**
   * Used for albums and tracks. The artist name for albums or the album name for tracks.
   */
  parentTitle?: string | undefined;
};

export type GetLibraryMatchesResponse = {
  /**
   * 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
   */
  mediaContainerWithMetadata?: shared.MediaContainerWithMetadata | undefined;
  headers: { [k: string]: Array<string> };
};

/** @internal */
export type GetLibraryMatchesRequest$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;
  type?: number | undefined;
  includeFullMetadata: number;
  includeAncestorMetadata: number;
  includeAlternateMetadataSources: number;
  guid?: string | undefined;
  title?: string | undefined;
  year?: number | undefined;
  path?: string | undefined;
  grandparentTitle?: string | undefined;
  grandparentYear?: number | undefined;
  parentIndex?: number | undefined;
  index?: number | undefined;
  originallyAvailableAt?: string | undefined;
  parentTitle?: string | undefined;
};

/** @internal */
export const GetLibraryMatchesRequest$outboundSchema: z.ZodType<
  GetLibraryMatchesRequest$Outbound,
  z.ZodTypeDef,
  GetLibraryMatchesRequest
> = 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(),
  type: shared.MediaType$outboundSchema.optional(),
  includeFullMetadata: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  includeAncestorMetadata: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  includeAlternateMetadataSources: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  guid: z.string().optional(),
  title: z.string().optional(),
  year: z.number().int().optional(),
  path: z.string().optional(),
  grandparentTitle: z.string().optional(),
  grandparentYear: z.number().int().optional(),
  parentIndex: z.number().int().optional(),
  index: z.number().int().optional(),
  originallyAvailableAt: z.string().optional(),
  parentTitle: 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 getLibraryMatchesRequestToJSON(
  getLibraryMatchesRequest: GetLibraryMatchesRequest,
): string {
  return JSON.stringify(
    GetLibraryMatchesRequest$outboundSchema.parse(getLibraryMatchesRequest),
  );
}

/** @internal */
export const GetLibraryMatchesResponse$inboundSchema: z.ZodType<
  GetLibraryMatchesResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  MediaContainerWithMetadata: shared.MediaContainerWithMetadata$inboundSchema
    .optional(),
  Headers: z.record(z.array(z.string())).default({}),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
    "MediaContainerWithMetadata": "mediaContainerWithMetadata",
    "Headers": "headers",
  });
});

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