/*
 * 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 GetTemplateGlobals = {
  /**
   * 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 GetTemplateRequest = {
  /**
   * 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 guid of the item for which to get the template
   */
  guid?: string | undefined;
};

/**
 * A media subscription contains a representation of metadata desired to be recorded
 *
 * @remarks
 */
export type MediaSubscription = {
  /**
   * The title of this subscription type
   */
  title?: string | undefined;
  /**
   * Metadata type number
   */
  type?: number | undefined;
  airingsType?: string | undefined;
  createdAt?: number | undefined;
  /**
   * Media Matching Hints
   */
  directory?: { [k: string]: any } | undefined;
  /**
   * Only included if `includeStorage` is specified
   */
  durationTotal?: number | undefined;
  key?: string | undefined;
  librarySectionTitle?: string | undefined;
  locationPath?: string | undefined;
  mediaGrabOperation?: Array<shared.MediaGrabOperation> | undefined;
  /**
   * Media Matching Hints
   */
  playlist?: { [k: string]: any } | undefined;
  setting?: Array<shared.Setting> | undefined;
  /**
   * Only included if `includeStorage` is specified
   */
  storageTotal?: number | undefined;
  /**
   * Where this subscription will record to
   */
  targetLibrarySectionID?: number | undefined;
  /**
   * The library section location id for where the item is to be recorded
   */
  targetSectionLocationID?: number | undefined;
  /**
   * Media Matching Hints
   */
  video?: { [k: string]: any } | undefined;
  /**
   * Parameter string for creating this subscription
   */
  parameters?: string | undefined;
  selected?: boolean | undefined;
};

export type SubscriptionTemplate = {
  mediaSubscription?: Array<MediaSubscription> | 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 GetTemplateMediaContainer = {
  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;
  subscriptionTemplate?: Array<SubscriptionTemplate> | undefined;
};

/**
 * OK
 */
export type GetTemplateResponseBody = {
  mediaContainer?: GetTemplateMediaContainer | undefined;
};

export type GetTemplateResponse = {
  /**
   * 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?: GetTemplateResponseBody | undefined;
  headers: { [k: string]: Array<string> };
};

/** @internal */
export type GetTemplateRequest$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;
  guid?: string | undefined;
};

/** @internal */
export const GetTemplateRequest$outboundSchema: z.ZodType<
  GetTemplateRequest$Outbound,
  z.ZodTypeDef,
  GetTemplateRequest
> = 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(),
  guid: 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 getTemplateRequestToJSON(
  getTemplateRequest: GetTemplateRequest,
): string {
  return JSON.stringify(
    GetTemplateRequest$outboundSchema.parse(getTemplateRequest),
  );
}

/** @internal */
export const MediaSubscription$inboundSchema: z.ZodType<
  MediaSubscription,
  z.ZodTypeDef,
  unknown
> = z.object({
  title: z.string().optional(),
  type: z.number().int().optional(),
  airingsType: z.string().optional(),
  createdAt: z.number().int().optional(),
  Directory: z.record(z.any()).optional(),
  durationTotal: z.number().int().optional(),
  key: z.string().optional(),
  librarySectionTitle: z.string().optional(),
  locationPath: z.string().optional(),
  MediaGrabOperation: z.array(shared.MediaGrabOperation$inboundSchema)
    .optional(),
  Playlist: z.record(z.any()).optional(),
  Setting: z.array(shared.Setting$inboundSchema).optional(),
  storageTotal: z.number().int().optional(),
  targetLibrarySectionID: z.number().int().optional(),
  targetSectionLocationID: z.number().int().optional(),
  Video: z.record(z.any()).optional(),
  parameters: z.string().optional(),
  selected: z.boolean().optional(),
}).transform((v) => {
  return remap$(v, {
    "Directory": "directory",
    "MediaGrabOperation": "mediaGrabOperation",
    "Playlist": "playlist",
    "Setting": "setting",
    "Video": "video",
  });
});

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

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

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

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

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

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

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

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

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