/*
 * 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 {
  MediaGrabOperation,
  MediaGrabOperation$inboundSchema,
} from "./mediagraboperation.js";
import { Setting, Setting$inboundSchema } from "./setting.js";

export enum AiringsType {
  NewAiringsOnly = "New Airings Only",
  NewAndRepeatAirings = "New and Repeat Airings",
}

/**
 * A media subscription contains a representation of metadata desired to be recorded
 *
 * @remarks
 */
export type MediaSubscription = {
  title?: string | undefined;
  /**
   * The metadata type of the root item of the subscription
   */
  type?: number | undefined;
  airingsType?: AiringsType | 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<MediaGrabOperation> | undefined;
  /**
   * Media Matching Hints
   */
  playlist?: { [k: string]: any } | undefined;
  setting?: Array<Setting> | undefined;
  /**
   * Only included if `includeStorage` is specified
   */
  storageTotal?: number | undefined;
  /**
   * The library section id for where the item is to be recorded
   */
  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;
};

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

/** @internal */
export const MediaSubscription$inboundSchema: z.ZodType<
  MediaSubscription,
  z.ZodTypeDef,
  unknown
> = z.object({
  title: z.string().optional(),
  type: z.number().int().optional(),
  airingsType: AiringsType$inboundSchema.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(MediaGrabOperation$inboundSchema).optional(),
  Playlist: z.record(z.any()).optional(),
  Setting: z.array(Setting$inboundSchema).optional(),
  storageTotal: z.number().int().optional(),
  targetLibrarySectionID: z.number().int().optional(),
  targetSectionLocationID: z.number().int().optional(),
  Video: z.record(z.any()).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`,
  );
}
