/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 6b955609daf1
 */

import * as z from "zod/v4";
import { safeParse } from "../../lib/schemas.js";
import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
import { discriminatedUnion } from "../../types/discriminatedUnion.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { BaseModelCard, BaseModelCard$inboundSchema } from "./basemodelcard.js";
import { FTModelCard, FTModelCard$inboundSchema } from "./ftmodelcard.js";

export type ModelListData =
  | BaseModelCard
  | FTModelCard
  | discriminatedUnionTypes.Unknown<"type">;

export type ModelList = {
  object: string;
  data?:
    | Array<
      BaseModelCard | FTModelCard | discriminatedUnionTypes.Unknown<"type">
    >
    | undefined;
};

/** @internal */
export const ModelListData$inboundSchema: z.ZodType<ModelListData, unknown> =
  discriminatedUnion("type", {
    base: BaseModelCard$inboundSchema,
    ["fine-tuned"]: FTModelCard$inboundSchema,
  });

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

/** @internal */
export const ModelList$inboundSchema: z.ZodType<ModelList, unknown> = z.object({
  object: z.string().default("list"),
  data: z.array(
    discriminatedUnion("type", {
      base: BaseModelCard$inboundSchema,
      ["fine-tuned"]: FTModelCard$inboundSchema,
    }),
  ).optional(),
});

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