/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { CheckpointOut, CheckpointOut$inboundSchema } from "./checkpointout.js";
import {
  CompletionTrainingParameters,
  CompletionTrainingParameters$inboundSchema,
} from "./completiontrainingparameters.js";
import { EventOut, EventOut$inboundSchema } from "./eventout.js";
import {
  GithubRepositoryOut,
  GithubRepositoryOut$inboundSchema,
} from "./githubrepositoryout.js";
import {
  JobMetadataOut,
  JobMetadataOut$inboundSchema,
} from "./jobmetadataout.js";
import {
  WandbIntegrationOut,
  WandbIntegrationOut$inboundSchema,
} from "./wandbintegrationout.js";

export const CompletionDetailedJobOutStatus = {
  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 CompletionDetailedJobOutStatus = ClosedEnum<
  typeof CompletionDetailedJobOutStatus
>;

export const CompletionDetailedJobOutObject = {
  Job: "job",
} as const;
export type CompletionDetailedJobOutObject = ClosedEnum<
  typeof CompletionDetailedJobOutObject
>;

export type CompletionDetailedJobOutIntegrations = WandbIntegrationOut;

export const CompletionDetailedJobOutJobType = {
  Completion: "completion",
} as const;
export type CompletionDetailedJobOutJobType = ClosedEnum<
  typeof CompletionDetailedJobOutJobType
>;

export type CompletionDetailedJobOutRepositories = GithubRepositoryOut;

export type CompletionDetailedJobOut = {
  id: string;
  autoStart: boolean;
  /**
   * The name of the model to fine-tune.
   */
  model: string;
  status: CompletionDetailedJobOutStatus;
  createdAt: number;
  modifiedAt: number;
  trainingFiles: Array<string>;
  validationFiles?: Array<string> | null | undefined;
  object: CompletionDetailedJobOutObject | undefined;
  fineTunedModel?: string | null | undefined;
  suffix?: string | null | undefined;
  integrations?: Array<WandbIntegrationOut> | null | undefined;
  trainedTokens?: number | null | undefined;
  metadata?: JobMetadataOut | null | undefined;
  jobType: CompletionDetailedJobOutJobType | undefined;
  hyperparameters: CompletionTrainingParameters;
  repositories?: Array<GithubRepositoryOut> | 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<EventOut> | undefined;
  checkpoints?: Array<CheckpointOut> | undefined;
};

/** @internal */
export const CompletionDetailedJobOutStatus$inboundSchema: z.ZodNativeEnum<
  typeof CompletionDetailedJobOutStatus
> = z.nativeEnum(CompletionDetailedJobOutStatus);

/** @internal */
export const CompletionDetailedJobOutObject$inboundSchema: z.ZodNativeEnum<
  typeof CompletionDetailedJobOutObject
> = z.nativeEnum(CompletionDetailedJobOutObject);

/** @internal */
export const CompletionDetailedJobOutIntegrations$inboundSchema: z.ZodType<
  CompletionDetailedJobOutIntegrations,
  z.ZodTypeDef,
  unknown
> = WandbIntegrationOut$inboundSchema;

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

/** @internal */
export const CompletionDetailedJobOutJobType$inboundSchema: z.ZodNativeEnum<
  typeof CompletionDetailedJobOutJobType
> = z.nativeEnum(CompletionDetailedJobOutJobType);

/** @internal */
export const CompletionDetailedJobOutRepositories$inboundSchema: z.ZodType<
  CompletionDetailedJobOutRepositories,
  z.ZodTypeDef,
  unknown
> = GithubRepositoryOut$inboundSchema;

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

/** @internal */
export const CompletionDetailedJobOut$inboundSchema: z.ZodType<
  CompletionDetailedJobOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  auto_start: z.boolean(),
  model: z.string(),
  status: CompletionDetailedJobOutStatus$inboundSchema,
  created_at: z.number().int(),
  modified_at: z.number().int(),
  training_files: z.array(z.string()),
  validation_files: z.nullable(z.array(z.string())).optional(),
  object: CompletionDetailedJobOutObject$inboundSchema.default("job"),
  fine_tuned_model: z.nullable(z.string()).optional(),
  suffix: z.nullable(z.string()).optional(),
  integrations: z.nullable(z.array(WandbIntegrationOut$inboundSchema))
    .optional(),
  trained_tokens: z.nullable(z.number().int()).optional(),
  metadata: z.nullable(JobMetadataOut$inboundSchema).optional(),
  job_type: CompletionDetailedJobOutJobType$inboundSchema.default("completion"),
  hyperparameters: CompletionTrainingParameters$inboundSchema,
  repositories: z.array(GithubRepositoryOut$inboundSchema).optional(),
  events: z.array(EventOut$inboundSchema).optional(),
  checkpoints: z.array(CheckpointOut$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 completionDetailedJobOutFromJSON(
  jsonString: string,
): SafeParseResult<CompletionDetailedJobOut, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CompletionDetailedJobOut$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CompletionDetailedJobOut' from JSON`,
  );
}
