/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.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 Data =
  | (BaseModelCard & { type: "base" })
  | (FTModelCard & { type: "fine-tuned" });

export type ModelList = {
  object: string | undefined;
  data?:
    | Array<
      | (BaseModelCard & { type: "base" })
      | (FTModelCard & { type: "fine-tuned" })
    >
    | undefined;
};

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

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

/** @internal */
export const ModelList$inboundSchema: z.ZodType<
  ModelList,
  z.ZodTypeDef,
  unknown
> = z.object({
  object: z.string().default("list"),
  data: z.array(
    z.union([
      BaseModelCard$inboundSchema.and(z.object({ type: z.literal("base") })),
      FTModelCard$inboundSchema.and(
        z.object({ type: z.literal("fine-tuned") }),
      ),
    ]),
  ).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`,
  );
}
