/*
 * 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 { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type UpdateAttackChallengeModeRequestBody2 = {
  projectId: string;
  attackModeEnabled: boolean;
};

export type UpdateAttackChallengeModeRequestBody1 = {
  projectId: string;
  attackModeEnabled: boolean;
  attackModeActiveUntil: number;
};

export type UpdateAttackChallengeModeRequestBody =
  | UpdateAttackChallengeModeRequestBody1
  | UpdateAttackChallengeModeRequestBody2;

export type UpdateAttackChallengeModeRequest = {
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
  requestBody:
    | UpdateAttackChallengeModeRequestBody1
    | UpdateAttackChallengeModeRequestBody2;
};

export type UpdateAttackChallengeModeResponseBody = {
  attackModeEnabled: boolean;
  attackModeUpdatedAt: number;
};

/** @internal */
export type UpdateAttackChallengeModeRequestBody2$Outbound = {
  projectId: string;
  attackModeEnabled: boolean;
};

/** @internal */
export const UpdateAttackChallengeModeRequestBody2$outboundSchema: z.ZodType<
  UpdateAttackChallengeModeRequestBody2$Outbound,
  z.ZodTypeDef,
  UpdateAttackChallengeModeRequestBody2
> = z.object({
  projectId: z.string(),
  attackModeEnabled: z.boolean(),
});

export function updateAttackChallengeModeRequestBody2ToJSON(
  updateAttackChallengeModeRequestBody2: UpdateAttackChallengeModeRequestBody2,
): string {
  return JSON.stringify(
    UpdateAttackChallengeModeRequestBody2$outboundSchema.parse(
      updateAttackChallengeModeRequestBody2,
    ),
  );
}

/** @internal */
export type UpdateAttackChallengeModeRequestBody1$Outbound = {
  projectId: string;
  attackModeEnabled: boolean;
  attackModeActiveUntil: number;
};

/** @internal */
export const UpdateAttackChallengeModeRequestBody1$outboundSchema: z.ZodType<
  UpdateAttackChallengeModeRequestBody1$Outbound,
  z.ZodTypeDef,
  UpdateAttackChallengeModeRequestBody1
> = z.object({
  projectId: z.string(),
  attackModeEnabled: z.boolean(),
  attackModeActiveUntil: z.number(),
});

export function updateAttackChallengeModeRequestBody1ToJSON(
  updateAttackChallengeModeRequestBody1: UpdateAttackChallengeModeRequestBody1,
): string {
  return JSON.stringify(
    UpdateAttackChallengeModeRequestBody1$outboundSchema.parse(
      updateAttackChallengeModeRequestBody1,
    ),
  );
}

/** @internal */
export type UpdateAttackChallengeModeRequestBody$Outbound =
  | UpdateAttackChallengeModeRequestBody1$Outbound
  | UpdateAttackChallengeModeRequestBody2$Outbound;

/** @internal */
export const UpdateAttackChallengeModeRequestBody$outboundSchema: z.ZodType<
  UpdateAttackChallengeModeRequestBody$Outbound,
  z.ZodTypeDef,
  UpdateAttackChallengeModeRequestBody
> = smartUnion([
  z.lazy(() => UpdateAttackChallengeModeRequestBody1$outboundSchema),
  z.lazy(() => UpdateAttackChallengeModeRequestBody2$outboundSchema),
]);

export function updateAttackChallengeModeRequestBodyToJSON(
  updateAttackChallengeModeRequestBody: UpdateAttackChallengeModeRequestBody,
): string {
  return JSON.stringify(
    UpdateAttackChallengeModeRequestBody$outboundSchema.parse(
      updateAttackChallengeModeRequestBody,
    ),
  );
}

/** @internal */
export type UpdateAttackChallengeModeRequest$Outbound = {
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody:
    | UpdateAttackChallengeModeRequestBody1$Outbound
    | UpdateAttackChallengeModeRequestBody2$Outbound;
};

/** @internal */
export const UpdateAttackChallengeModeRequest$outboundSchema: z.ZodType<
  UpdateAttackChallengeModeRequest$Outbound,
  z.ZodTypeDef,
  UpdateAttackChallengeModeRequest
> = z.object({
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: smartUnion([
    z.lazy(() => UpdateAttackChallengeModeRequestBody1$outboundSchema),
    z.lazy(() => UpdateAttackChallengeModeRequestBody2$outboundSchema),
  ]),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function updateAttackChallengeModeRequestToJSON(
  updateAttackChallengeModeRequest: UpdateAttackChallengeModeRequest,
): string {
  return JSON.stringify(
    UpdateAttackChallengeModeRequest$outboundSchema.parse(
      updateAttackChallengeModeRequest,
    ),
  );
}

/** @internal */
export const UpdateAttackChallengeModeResponseBody$inboundSchema: z.ZodType<
  UpdateAttackChallengeModeResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  attackModeEnabled: types.boolean(),
  attackModeUpdatedAt: types.number(),
});

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