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

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 { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  JudgeClassificationOutput,
  JudgeClassificationOutput$inboundSchema,
} from "./judgeclassificationoutput.js";
import {
  JudgeRegressionOutput,
  JudgeRegressionOutput$inboundSchema,
} from "./judgeregressionoutput.js";

export type JudgePreviewOutput =
  | (JudgeClassificationOutput & { type: "CLASSIFICATION" })
  | (JudgeRegressionOutput & { type: "REGRESSION" });

export type JudgePreview = {
  id: string;
  createdAt: Date;
  updatedAt: Date;
  deletedAt: Date | null;
  ownerId: string;
  workspaceId: string;
  name: string;
  description: string;
  modelName: string;
  output:
    | (JudgeClassificationOutput & { type: "CLASSIFICATION" })
    | (JudgeRegressionOutput & { type: "REGRESSION" });
  instructions: string;
  tools: Array<string>;
  upRevision?: string | null | undefined;
  downRevision?: string | null | undefined;
  baseRevision?: string | null | undefined;
};

/** @internal */
export const JudgePreviewOutput$inboundSchema: z.ZodType<
  JudgePreviewOutput,
  z.ZodTypeDef,
  unknown
> = z.union([
  JudgeClassificationOutput$inboundSchema.and(
    z.object({ type: z.literal("CLASSIFICATION") }),
  ),
  JudgeRegressionOutput$inboundSchema.and(
    z.object({ type: z.literal("REGRESSION") }),
  ),
]);

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

/** @internal */
export const JudgePreview$inboundSchema: z.ZodType<
  JudgePreview,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  created_at: z.string().datetime({ offset: true }).transform(v => new Date(v)),
  updated_at: z.string().datetime({ offset: true }).transform(v => new Date(v)),
  deleted_at: z.nullable(
    z.string().datetime({ offset: true }).transform(v => new Date(v)),
  ),
  owner_id: z.string(),
  workspace_id: z.string(),
  name: z.string(),
  description: z.string(),
  model_name: z.string(),
  output: z.union([
    JudgeClassificationOutput$inboundSchema.and(
      z.object({ type: z.literal("CLASSIFICATION") }),
    ),
    JudgeRegressionOutput$inboundSchema.and(
      z.object({ type: z.literal("REGRESSION") }),
    ),
  ]),
  instructions: z.string(),
  tools: z.array(z.string()),
  up_revision: z.nullable(z.string()).optional(),
  down_revision: z.nullable(z.string()).optional(),
  base_revision: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "updated_at": "updatedAt",
    "deleted_at": "deletedAt",
    "owner_id": "ownerId",
    "workspace_id": "workspaceId",
    "model_name": "modelName",
    "up_revision": "upRevision",
    "down_revision": "downRevision",
    "base_revision": "baseRevision",
  });
});

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