/*
 * 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 CreateSubscriptionGlobals = {
  /**
   * 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;
};

/**
 * Hints describing what we're looking for.  Note: The hint `ratingKey` is required for downloading from a PMS remote.
 */
export type Hints = {};

/**
 * Subscription preferences.
 */
export type CreateSubscriptionPrefs = {};

/**
 * Subscription parameters.
 *
 * @remarks
 *   - `mediaProviderID`: Required for downloads to indicate which MP the subscription will download into
 *   - `source`: Required for downloads to indicate the source of the downloaded content.
 */
export type Params = {};

export type CreateSubscriptionRequest = {
  /**
   * 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 library section into which we'll grab the media.  Not actually required when the subscription is to a playlist.
   */
  targetLibrarySectionID?: number | undefined;
  /**
   * The section location into which to grab.
   */
  targetSectionLocationID?: number | undefined;
  /**
   * The type of the thing we're subscribing too (e.g. show, season).
   */
  type?: number | undefined;
  /**
   * Hints describing what we're looking for.  Note: The hint `ratingKey` is required for downloading from a PMS remote.
   */
  hints?: Hints | undefined;
  /**
   * Subscription preferences.
   */
  prefs?: CreateSubscriptionPrefs | undefined;
  /**
   * Subscription parameters.
   *
   * @remarks
   *   - `mediaProviderID`: Required for downloads to indicate which MP the subscription will download into
   *   - `source`: Required for downloads to indicate the source of the downloaded content.
   */
  params?: Params | 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 CreateSubscriptionMediaContainer = {
  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;
  mediaSubscription?: Array<shared.MediaSubscription> | undefined;
};

/**
 * OK
 */
export type CreateSubscriptionResponseBody = {
  mediaContainer?: CreateSubscriptionMediaContainer | undefined;
};

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

/** @internal */
export type Hints$Outbound = {};

/** @internal */
export const Hints$outboundSchema: z.ZodType<
  Hints$Outbound,
  z.ZodTypeDef,
  Hints
> = z.object({});

export function hintsToJSON(hints: Hints): string {
  return JSON.stringify(Hints$outboundSchema.parse(hints));
}

/** @internal */
export type CreateSubscriptionPrefs$Outbound = {};

/** @internal */
export const CreateSubscriptionPrefs$outboundSchema: z.ZodType<
  CreateSubscriptionPrefs$Outbound,
  z.ZodTypeDef,
  CreateSubscriptionPrefs
> = z.object({});

export function createSubscriptionPrefsToJSON(
  createSubscriptionPrefs: CreateSubscriptionPrefs,
): string {
  return JSON.stringify(
    CreateSubscriptionPrefs$outboundSchema.parse(createSubscriptionPrefs),
  );
}

/** @internal */
export type Params$Outbound = {};

/** @internal */
export const Params$outboundSchema: z.ZodType<
  Params$Outbound,
  z.ZodTypeDef,
  Params
> = z.object({});

export function paramsToJSON(params: Params): string {
  return JSON.stringify(Params$outboundSchema.parse(params));
}

/** @internal */
export type CreateSubscriptionRequest$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;
  targetLibrarySectionID?: number | undefined;
  targetSectionLocationID?: number | undefined;
  type?: number | undefined;
  hints?: Hints$Outbound | undefined;
  prefs?: CreateSubscriptionPrefs$Outbound | undefined;
  params?: Params$Outbound | undefined;
};

/** @internal */
export const CreateSubscriptionRequest$outboundSchema: z.ZodType<
  CreateSubscriptionRequest$Outbound,
  z.ZodTypeDef,
  CreateSubscriptionRequest
> = 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(),
  targetLibrarySectionID: z.number().int().optional(),
  targetSectionLocationID: z.number().int().optional(),
  type: z.number().int().optional(),
  hints: z.lazy(() => Hints$outboundSchema).optional(),
  prefs: z.lazy(() => CreateSubscriptionPrefs$outboundSchema).optional(),
  params: z.lazy(() => Params$outboundSchema).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 createSubscriptionRequestToJSON(
  createSubscriptionRequest: CreateSubscriptionRequest,
): string {
  return JSON.stringify(
    CreateSubscriptionRequest$outboundSchema.parse(createSubscriptionRequest),
  );
}

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

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

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

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

/** @internal */
export const CreateSubscriptionResponse$inboundSchema: z.ZodType<
  CreateSubscriptionResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  object: z.lazy(() => CreateSubscriptionResponseBody$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 createSubscriptionResponseFromJSON(
  jsonString: string,
): SafeParseResult<CreateSubscriptionResponse, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CreateSubscriptionResponse$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CreateSubscriptionResponse' from JSON`,
  );
}
