/*
 * 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 JobsApiRoutesFineTuningUpdateFineTunedModelRequest = {
  /**
   * The ID of the model to update.
   */
  modelId: string;
  updateFTModelIn: components.UpdateFTModelIn;
};

/**
 * OK
 */
export type JobsApiRoutesFineTuningUpdateFineTunedModelResponse =
  | (components.ClassifierFTModelOut & { modelType: "classifier" })
  | (components.CompletionFTModelOut & { modelType: "completion" });

/** @internal */
export type JobsApiRoutesFineTuningUpdateFineTunedModelRequest$Outbound = {
  model_id: string;
  UpdateFTModelIn: components.UpdateFTModelIn$Outbound;
};

/** @internal */
export const JobsApiRoutesFineTuningUpdateFineTunedModelRequest$outboundSchema:
  z.ZodType<
    JobsApiRoutesFineTuningUpdateFineTunedModelRequest$Outbound,
    z.ZodTypeDef,
    JobsApiRoutesFineTuningUpdateFineTunedModelRequest
  > = z.object({
    modelId: z.string(),
    updateFTModelIn: components.UpdateFTModelIn$outboundSchema,
  }).transform((v) => {
    return remap$(v, {
      modelId: "model_id",
      updateFTModelIn: "UpdateFTModelIn",
    });
  });

export function jobsApiRoutesFineTuningUpdateFineTunedModelRequestToJSON(
  jobsApiRoutesFineTuningUpdateFineTunedModelRequest:
    JobsApiRoutesFineTuningUpdateFineTunedModelRequest,
): string {
  return JSON.stringify(
    JobsApiRoutesFineTuningUpdateFineTunedModelRequest$outboundSchema.parse(
      jobsApiRoutesFineTuningUpdateFineTunedModelRequest,
    ),
  );
}

/** @internal */
export const JobsApiRoutesFineTuningUpdateFineTunedModelResponse$inboundSchema:
  z.ZodType<
    JobsApiRoutesFineTuningUpdateFineTunedModelResponse,
    z.ZodTypeDef,
    unknown
  > = z.union([
    components.ClassifierFTModelOut$inboundSchema.and(
      z.object({ model_type: z.literal("classifier") }).transform((v) => ({
        modelType: v.model_type,
      })),
    ),
    components.CompletionFTModelOut$inboundSchema.and(
      z.object({ model_type: z.literal("completion") }).transform((v) => ({
        modelType: v.model_type,
      })),
    ),
  ]);

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