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

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 {
  ClassifierFineTuningJob,
  ClassifierFineTuningJob$inboundSchema,
} from "./classifierfinetuningjob.js";
import {
  CompletionFineTuningJob,
  CompletionFineTuningJob$inboundSchema,
} from "./completionfinetuningjob.js";

export type ListFineTuningJobsResponseData =
  | ClassifierFineTuningJob
  | CompletionFineTuningJob
  | discriminatedUnionTypes.Unknown<"jobType">;

export type ListFineTuningJobsResponse = {
  data?:
    | Array<
      | ClassifierFineTuningJob
      | CompletionFineTuningJob
      | discriminatedUnionTypes.Unknown<"jobType">
    >
    | undefined;
  object: "list";
  total: number;
};

/** @internal */
export const ListFineTuningJobsResponseData$inboundSchema: z.ZodType<
  ListFineTuningJobsResponseData,
  unknown
> = discriminatedUnion("job_type", {
  classifier: ClassifierFineTuningJob$inboundSchema,
  completion: CompletionFineTuningJob$inboundSchema,
}, { outputPropertyName: "jobType" });

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

/** @internal */
export const ListFineTuningJobsResponse$inboundSchema: z.ZodType<
  ListFineTuningJobsResponse,
  unknown
> = z.object({
  data: z.array(
    discriminatedUnion("job_type", {
      classifier: ClassifierFineTuningJob$inboundSchema,
      completion: CompletionFineTuningJob$inboundSchema,
    }, { outputPropertyName: "jobType" }),
  ).optional(),
  object: z.literal("list").default("list"),
  total: z.int(),
});

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