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

import * as z from "zod/v4";
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 { FilterPayload, FilterPayload$inboundSchema } from "./filterpayload.js";
import { Judge, Judge$inboundSchema } from "./judge.js";

export type Campaign = {
  id: string;
  createdAt: Date;
  updatedAt: Date;
  deletedAt: Date | null;
  name: string;
  ownerId: string;
  workspaceId: string;
  description: string;
  maxNbEvents: number;
  searchParams: FilterPayload;
  judge: Judge;
};

/** @internal */
export const Campaign$inboundSchema: z.ZodType<Campaign, 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)),
  ),
  name: z.string(),
  owner_id: z.string(),
  workspace_id: z.string(),
  description: z.string(),
  max_nb_events: z.int(),
  search_params: FilterPayload$inboundSchema,
  judge: Judge$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "updated_at": "updatedAt",
    "deleted_at": "deletedAt",
    "owner_id": "ownerId",
    "workspace_id": "workspaceId",
    "max_nb_events": "maxNbEvents",
    "search_params": "searchParams",
  });
});

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