/*
 * 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 {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type FilterPivot = {
  title?: string | undefined;
  type?: string | undefined;
  context?: string | undefined;
  id?: string | undefined;
  key?: string | undefined;
  symbol?: string | undefined;
};

/**
 * Each `Filter` object contains a description of the filter. Note that it is not an exhaustive list of the full media query language, but an important subset useful for top-level API.
 *
 * @remarks
 */
export type Filter = {
  /**
   * The title for the filter.
   */
  title?: string | undefined;
  type?: string | undefined;
  art?: string | undefined;
  content?: boolean | undefined;
  /**
   * This represents the filter name used for the filter, which can be used to construct complex media queries with.
   */
  filter?: string | undefined;
  hasPrefs?: boolean | undefined;
  hasStoreServices?: boolean | undefined;
  hubKey?: string | undefined;
  identifier?: string | undefined;
  /**
   * This provides the endpoint where the possible range of values for the filter can be retrieved (e.g. for a "Genre" filter, it returns a list of all the genres in the library). This will include a `type` argument that matches the metadata type of the Type element.
   */
  key?: string | undefined;
  lastAccessedAt?: number | undefined;
  pivot?: Array<FilterPivot> | undefined;
  share?: number | undefined;
  thumb?: string | undefined;
  titleBar?: string | undefined;
  /**
   * This is either `string`, `integer`, or `boolean`, and describes the type of values used for the filter.
   */
  filterType?: string | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const FilterPivot$inboundSchema: z.ZodType<
  FilterPivot,
  z.ZodTypeDef,
  unknown
> = z.object({
  title: z.string().optional(),
  type: z.string().optional(),
  context: z.string().optional(),
  id: z.string().optional(),
  key: z.string().optional(),
  symbol: z.string().optional(),
});

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

/** @internal */
export const Filter$inboundSchema: z.ZodType<Filter, z.ZodTypeDef, unknown> =
  collectExtraKeys$(
    z.object({
      title: z.string().optional(),
      type: z.string().optional(),
      art: z.string().optional(),
      content: z.boolean().optional(),
      filter: z.string().optional(),
      hasPrefs: z.boolean().optional(),
      hasStoreServices: z.boolean().optional(),
      hubKey: z.string().optional(),
      identifier: z.string().optional(),
      key: z.string().optional(),
      lastAccessedAt: z.number().int().optional(),
      Pivot: z.array(z.lazy(() => FilterPivot$inboundSchema)).optional(),
      share: z.number().int().optional(),
      thumb: z.string().optional(),
      titleBar: z.string().optional(),
      filterType: z.string().optional(),
    }).catchall(z.any()),
    "additionalProperties",
    true,
  ).transform((v) => {
    return remap$(v, {
      "Pivot": "pivot",
    });
  });

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