/*
 * 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 {
  CompletionTrainingParameters,
  CompletionTrainingParameters$inboundSchema,
} from "./completiontrainingparameters.js";
import {
  GithubRepositoryOut,
  GithubRepositoryOut$inboundSchema,
} from "./githubrepositoryout.js";
import {
  JobMetadataOut,
  JobMetadataOut$inboundSchema,
} from "./jobmetadataout.js";
import {
  WandbIntegrationOut,
  WandbIntegrationOut$inboundSchema,
} from "./wandbintegrationout.js";

/**
 * The current status of the fine-tuning job.
 */
export const Status = {
  Queued: "QUEUED",
  Started: "STARTED",
  Validating: "VALIDATING",
  Validated: "VALIDATED",
  Running: "RUNNING",
  FailedValidation: "FAILED_VALIDATION",
  Failed: "FAILED",
  Success: "SUCCESS",
  Cancelled: "CANCELLED",
  CancellationRequested: "CANCELLATION_REQUESTED",
} as const;
/**
 * The current status of the fine-tuning job.
 */
export type Status = ClosedEnum<typeof Status>;

/**
 * The object type of the fine-tuning job.
 */
export const CompletionJobOutObject = {
  Job: "job",
} as const;
/**
 * The object type of the fine-tuning job.
 */
export type CompletionJobOutObject = ClosedEnum<typeof CompletionJobOutObject>;

export type Integrations = WandbIntegrationOut;

/**
 * The type of job (`FT` for fine-tuning).
 */
export const JobType = {
  Completion: "completion",
} as const;
/**
 * The type of job (`FT` for fine-tuning).
 */
export type JobType = ClosedEnum<typeof JobType>;

export type Repositories = GithubRepositoryOut;

export type CompletionJobOut = {
  /**
   * The ID of the job.
   */
  id: string;
  autoStart: boolean;
  /**
   * The name of the model to fine-tune.
   */
  model: string;
  /**
   * The current status of the fine-tuning job.
   */
  status: Status;
  /**
   * The UNIX timestamp (in seconds) for when the fine-tuning job was created.
   */
  createdAt: number;
  /**
   * The UNIX timestamp (in seconds) for when the fine-tuning job was last modified.
   */
  modifiedAt: number;
  /**
   * A list containing the IDs of uploaded files that contain training data.
   */
  trainingFiles: Array<string>;
  /**
   * A list containing the IDs of uploaded files that contain validation data.
   */
  validationFiles?: Array<string> | null | undefined;
  /**
   * The object type of the fine-tuning job.
   */
  object: CompletionJobOutObject | undefined;
  /**
   * The name of the fine-tuned model that is being created. The value will be `null` if the fine-tuning job is still running.
   */
  fineTunedModel?: string | null | undefined;
  /**
   * Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
   */
  suffix?: string | null | undefined;
  /**
   * A list of integrations enabled for your fine-tuning job.
   */
  integrations?: Array<WandbIntegrationOut> | null | undefined;
  /**
   * Total number of tokens trained.
   */
  trainedTokens?: number | null | undefined;
  metadata?: JobMetadataOut | null | undefined;
  /**
   * The type of job (`FT` for fine-tuning).
   */
  jobType: JobType | undefined;
  hyperparameters: CompletionTrainingParameters;
  repositories?: Array<GithubRepositoryOut> | undefined;
};

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

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

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

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

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

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

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

/** @internal */
export const CompletionJobOut$inboundSchema: z.ZodType<
  CompletionJobOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  auto_start: z.boolean(),
  model: z.string(),
  status: Status$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: CompletionJobOutObject$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: JobType$inboundSchema.default("completion"),
  hyperparameters: CompletionTrainingParameters$inboundSchema,
  repositories: z.array(GithubRepositoryOut$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 completionJobOutFromJSON(
  jsonString: string,
): SafeParseResult<CompletionJobOut, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CompletionJobOut$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CompletionJobOut' from JSON`,
  );
}
