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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
import { discriminatedUnion } from "../../types/discriminatedUnion.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 JudgeOutputUnion =
  | JudgeClassificationOutput
  | JudgeRegressionOutput
  | discriminatedUnionTypes.Unknown<"type">;

export type Judge = {
  id: string;
  createdAt: Date;
  updatedAt: Date;
  deletedAt: Date | null;
  ownerId: string;
  workspaceId: string;
  name: string;
  description: string;
  modelName: string;
  output:
    | JudgeClassificationOutput
    | JudgeRegressionOutput
    | discriminatedUnionTypes.Unknown<"type">;
  instructions: string;
  tools: Array<string>;
  upRevision?: string | null | undefined;
  downRevision?: string | null | undefined;
  baseRevision?: string | null | undefined;
};

/** @internal */
export const JudgeOutputUnion$inboundSchema: z.ZodType<
  JudgeOutputUnion,
  unknown
> = discriminatedUnion("type", {
  CLASSIFICATION: JudgeClassificationOutput$inboundSchema,
  REGRESSION: JudgeRegressionOutput$inboundSchema,
});

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

/** @internal */
export const Judge$inboundSchema: z.ZodType<Judge, unknown> = z.object({
  id: z.string(),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  updated_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  deleted_at: z.nullable(
    z.iso.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: discriminatedUnion("type", {
    CLASSIFICATION: JudgeClassificationOutput$inboundSchema,
    REGRESSION: JudgeRegressionOutput$inboundSchema,
  }),
  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 judgeFromJSON(
  jsonString: string,
): SafeParseResult<Judge, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Judge$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Judge' from JSON`,
  );
}
