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

export type JobsApiRoutesFineTuningGetFineTuningJobRequest = {
  /**
   * The ID of the job to analyse.
   */
  jobId: string;
};

/**
 * OK
 */
export type JobsApiRoutesFineTuningGetFineTuningJobResponse =
  | (components.ClassifierDetailedJobOut & { jobType: "classifier" })
  | (components.CompletionDetailedJobOut & { jobType: "completion" });

/** @internal */
export type JobsApiRoutesFineTuningGetFineTuningJobRequest$Outbound = {
  job_id: string;
};

/** @internal */
export const JobsApiRoutesFineTuningGetFineTuningJobRequest$outboundSchema:
  z.ZodType<
    JobsApiRoutesFineTuningGetFineTuningJobRequest$Outbound,
    z.ZodTypeDef,
    JobsApiRoutesFineTuningGetFineTuningJobRequest
  > = z.object({
    jobId: z.string(),
  }).transform((v) => {
    return remap$(v, {
      jobId: "job_id",
    });
  });

export function jobsApiRoutesFineTuningGetFineTuningJobRequestToJSON(
  jobsApiRoutesFineTuningGetFineTuningJobRequest:
    JobsApiRoutesFineTuningGetFineTuningJobRequest,
): string {
  return JSON.stringify(
    JobsApiRoutesFineTuningGetFineTuningJobRequest$outboundSchema.parse(
      jobsApiRoutesFineTuningGetFineTuningJobRequest,
    ),
  );
}

/** @internal */
export const JobsApiRoutesFineTuningGetFineTuningJobResponse$inboundSchema:
  z.ZodType<
    JobsApiRoutesFineTuningGetFineTuningJobResponse,
    z.ZodTypeDef,
    unknown
  > = z.union([
    components.ClassifierDetailedJobOut$inboundSchema.and(
      z.object({ job_type: z.literal("classifier") }).transform((v) => ({
        jobType: v.job_type,
      })),
    ),
    components.CompletionDetailedJobOut$inboundSchema.and(
      z.object({ job_type: z.literal("completion") }).transform((v) => ({
        jobType: v.job_type,
      })),
    ),
  ]);

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