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

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 { smartUnion } from "../../types/smartUnion.js";
import * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

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

/**
 * OK
 */
export type JobsApiRoutesFineTuningCreateFineTuningJobResponse =
  | components.LegacyJobMetadata
  | components.ClassifierFineTuningJob
  | components.CompletionFineTuningJob
  | discriminatedUnionTypes.Unknown<"jobType">;

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

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

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

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