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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { Checkpoint, Checkpoint$inboundSchema } from "./checkpoint.js";
import {
  CompletionTrainingParameters,
  CompletionTrainingParameters$inboundSchema,
} from "./completiontrainingparameters.js";
import { Event, Event$inboundSchema } from "./event.js";
import {
  GithubRepository,
  GithubRepository$inboundSchema,
} from "./githubrepository.js";
import { JobMetadata, JobMetadata$inboundSchema } from "./jobmetadata.js";
import {
  WandbIntegrationResult,
  WandbIntegrationResult$inboundSchema,
} from "./wandbintegrationresult.js";

export const CompletionFineTuningJobDetailsStatus = {
  Queued: "QUEUED",
  Started: "STARTED",
  Validating: "VALIDATING",
  Validated: "VALIDATED",
  Running: "RUNNING",
  FailedValidation: "FAILED_VALIDATION",
  Failed: "FAILED",
  Success: "SUCCESS",
  Cancelled: "CANCELLED",
  CancellationRequested: "CANCELLATION_REQUESTED",
} as const;
export type CompletionFineTuningJobDetailsStatus = OpenEnum<
  typeof CompletionFineTuningJobDetailsStatus
>;

export type CompletionFineTuningJobDetailsIntegration = WandbIntegrationResult;

export type CompletionFineTuningJobDetailsRepository = GithubRepository;

export type CompletionFineTuningJobDetails = {
  id: string;
  autoStart: boolean;
  model: string;
  status: CompletionFineTuningJobDetailsStatus;
  createdAt: number;
  modifiedAt: number;
  trainingFiles: Array<string>;
  validationFiles?: Array<string> | null | undefined;
  object: "job";
  fineTunedModel?: string | null | undefined;
  suffix?: string | null | undefined;
  integrations?: Array<WandbIntegrationResult> | null | undefined;
  trainedTokens?: number | null | undefined;
  metadata?: JobMetadata | null | undefined;
  jobType: "completion";
  hyperparameters: CompletionTrainingParameters;
  repositories?: Array<GithubRepository> | undefined;
  /**
   * Event items are created every time the status of a fine-tuning job changes. The timestamped list of all events is accessible here.
   */
  events?: Array<Event> | undefined;
  checkpoints?: Array<Checkpoint> | undefined;
};

/** @internal */
export const CompletionFineTuningJobDetailsStatus$inboundSchema: z.ZodType<
  CompletionFineTuningJobDetailsStatus,
  unknown
> = openEnums.inboundSchema(CompletionFineTuningJobDetailsStatus);

/** @internal */
export const CompletionFineTuningJobDetailsIntegration$inboundSchema: z.ZodType<
  CompletionFineTuningJobDetailsIntegration,
  unknown
> = WandbIntegrationResult$inboundSchema;

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

/** @internal */
export const CompletionFineTuningJobDetailsRepository$inboundSchema: z.ZodType<
  CompletionFineTuningJobDetailsRepository,
  unknown
> = GithubRepository$inboundSchema;

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

/** @internal */
export const CompletionFineTuningJobDetails$inboundSchema: z.ZodType<
  CompletionFineTuningJobDetails,
  unknown
> = z.object({
  id: z.string(),
  auto_start: z.boolean(),
  model: z.string(),
  status: CompletionFineTuningJobDetailsStatus$inboundSchema,
  created_at: z.int(),
  modified_at: z.int(),
  training_files: z.array(z.string()),
  validation_files: z.nullable(z.array(z.string())).optional(),
  object: z.literal("job").default("job"),
  fine_tuned_model: z.nullable(z.string()).optional(),
  suffix: z.nullable(z.string()).optional(),
  integrations: z.nullable(z.array(WandbIntegrationResult$inboundSchema))
    .optional(),
  trained_tokens: z.nullable(z.int()).optional(),
  metadata: z.nullable(JobMetadata$inboundSchema).optional(),
  job_type: z.literal("completion"),
  hyperparameters: CompletionTrainingParameters$inboundSchema,
  repositories: z.array(GithubRepository$inboundSchema).optional(),
  events: z.array(Event$inboundSchema).optional(),
  checkpoints: z.array(Checkpoint$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "auto_start": "autoStart",
    "created_at": "createdAt",
    "modified_at": "modifiedAt",
    "training_files": "trainingFiles",
    "validation_files": "validationFiles",
    "fine_tuned_model": "fineTunedModel",
    "trained_tokens": "trainedTokens",
    "job_type": "jobType",
  });
});

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