/*
 * 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 { ClosedEnum } from "../types/enums.js";
import { smartUnion } from "../types/smartUnion.js";

export const PatchUrlProtectionBypassRequestBodyScope = {
  AliasProtectionOverride: "alias-protection-override",
} as const;
export type PatchUrlProtectionBypassRequestBodyScope = ClosedEnum<
  typeof PatchUrlProtectionBypassRequestBodyScope
>;

export const PatchUrlProtectionBypassRequestBodyAction = {
  Create: "create",
  Revoke: "revoke",
} as const;
export type PatchUrlProtectionBypassRequestBodyAction = ClosedEnum<
  typeof PatchUrlProtectionBypassRequestBodyAction
>;

export type Override = {
  scope: PatchUrlProtectionBypassRequestBodyScope;
  action: PatchUrlProtectionBypassRequestBodyAction;
};

export type PatchUrlProtectionBypassRequestBody3 = {
  override: Override;
};

/**
 * Invitation status for the user scoped bypass.
 */
export const PatchUrlProtectionBypassScopeAccess = {
  Denied: "denied",
  Granted: "granted",
} as const;
/**
 * Invitation status for the user scoped bypass.
 */
export type PatchUrlProtectionBypassScopeAccess = ClosedEnum<
  typeof PatchUrlProtectionBypassScopeAccess
>;

export type Scope2 = {
  /**
   * Specified user id for the scoped bypass.
   */
  userId?: string | undefined;
  /**
   * Specified email for the scoped bypass.
   */
  email: string;
  /**
   * Invitation status for the user scoped bypass.
   */
  access: PatchUrlProtectionBypassScopeAccess;
};

/**
 * Invitation status for the user scoped bypass.
 */
export const ScopeAccess = {
  Denied: "denied",
  Granted: "granted",
} as const;
/**
 * Invitation status for the user scoped bypass.
 */
export type ScopeAccess = ClosedEnum<typeof ScopeAccess>;

export type Scope1 = {
  /**
   * Specified user id for the scoped bypass.
   */
  userId: string;
  /**
   * Specified email for the scoped bypass.
   */
  email?: string | undefined;
  /**
   * Invitation status for the user scoped bypass.
   */
  access: ScopeAccess;
};

/**
 * Instructions for creating a user scoped protection bypass
 */
export type RequestBodyScope = Scope1 | Scope2;

export type PatchUrlProtectionBypassRequestBody2 = {
  /**
   * Instructions for creating a user scoped protection bypass
   */
  scope: Scope1 | Scope2;
};

/**
 * Optional instructions for revoking and regenerating a shareable link
 */
export type RequestBodyRevoke = {
  /**
   * Sharebale link to revoked
   */
  secret: string;
  /**
   * Whether or not a new shareable link should be created after the provided secret is revoked
   */
  regenerate: boolean;
};

export type PatchUrlProtectionBypassRequestBody1 = {
  /**
   * Optional time the shareable link is valid for in seconds. If not provided, the shareable link will never expire.
   */
  ttl?: number | undefined;
  /**
   * Optional instructions for revoking and regenerating a shareable link
   */
  revoke?: RequestBodyRevoke | undefined;
};

export type PatchUrlProtectionBypassRequestBody =
  | PatchUrlProtectionBypassRequestBody2
  | PatchUrlProtectionBypassRequestBody3
  | PatchUrlProtectionBypassRequestBody1;

export type PatchUrlProtectionBypassRequest = {
  /**
   * The alias or deployment ID
   */
  id: string;
  /**
   * 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?:
    | PatchUrlProtectionBypassRequestBody2
    | PatchUrlProtectionBypassRequestBody3
    | PatchUrlProtectionBypassRequestBody1
    | undefined;
};

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

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

/** @internal */
export type Override$Outbound = {
  scope: string;
  action: string;
};

/** @internal */
export const Override$outboundSchema: z.ZodType<
  Override$Outbound,
  z.ZodTypeDef,
  Override
> = z.object({
  scope: PatchUrlProtectionBypassRequestBodyScope$outboundSchema,
  action: PatchUrlProtectionBypassRequestBodyAction$outboundSchema,
});

export function overrideToJSON(override: Override): string {
  return JSON.stringify(Override$outboundSchema.parse(override));
}

/** @internal */
export type PatchUrlProtectionBypassRequestBody3$Outbound = {
  override: Override$Outbound;
};

/** @internal */
export const PatchUrlProtectionBypassRequestBody3$outboundSchema: z.ZodType<
  PatchUrlProtectionBypassRequestBody3$Outbound,
  z.ZodTypeDef,
  PatchUrlProtectionBypassRequestBody3
> = z.object({
  override: z.lazy(() => Override$outboundSchema),
});

export function patchUrlProtectionBypassRequestBody3ToJSON(
  patchUrlProtectionBypassRequestBody3: PatchUrlProtectionBypassRequestBody3,
): string {
  return JSON.stringify(
    PatchUrlProtectionBypassRequestBody3$outboundSchema.parse(
      patchUrlProtectionBypassRequestBody3,
    ),
  );
}

/** @internal */
export const PatchUrlProtectionBypassScopeAccess$outboundSchema:
  z.ZodNativeEnum<typeof PatchUrlProtectionBypassScopeAccess> = z.nativeEnum(
    PatchUrlProtectionBypassScopeAccess,
  );

/** @internal */
export type Scope2$Outbound = {
  userId?: string | undefined;
  email: string;
  access: string;
};

/** @internal */
export const Scope2$outboundSchema: z.ZodType<
  Scope2$Outbound,
  z.ZodTypeDef,
  Scope2
> = z.object({
  userId: z.string().optional(),
  email: z.string(),
  access: PatchUrlProtectionBypassScopeAccess$outboundSchema,
});

export function scope2ToJSON(scope2: Scope2): string {
  return JSON.stringify(Scope2$outboundSchema.parse(scope2));
}

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

/** @internal */
export type Scope1$Outbound = {
  userId: string;
  email?: string | undefined;
  access: string;
};

/** @internal */
export const Scope1$outboundSchema: z.ZodType<
  Scope1$Outbound,
  z.ZodTypeDef,
  Scope1
> = z.object({
  userId: z.string(),
  email: z.string().optional(),
  access: ScopeAccess$outboundSchema,
});

export function scope1ToJSON(scope1: Scope1): string {
  return JSON.stringify(Scope1$outboundSchema.parse(scope1));
}

/** @internal */
export type RequestBodyScope$Outbound = Scope1$Outbound | Scope2$Outbound;

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

export function requestBodyScopeToJSON(
  requestBodyScope: RequestBodyScope,
): string {
  return JSON.stringify(
    RequestBodyScope$outboundSchema.parse(requestBodyScope),
  );
}

/** @internal */
export type PatchUrlProtectionBypassRequestBody2$Outbound = {
  scope: Scope1$Outbound | Scope2$Outbound;
};

/** @internal */
export const PatchUrlProtectionBypassRequestBody2$outboundSchema: z.ZodType<
  PatchUrlProtectionBypassRequestBody2$Outbound,
  z.ZodTypeDef,
  PatchUrlProtectionBypassRequestBody2
> = z.object({
  scope: smartUnion([
    z.lazy(() => Scope1$outboundSchema),
    z.lazy(() => Scope2$outboundSchema),
  ]),
});

export function patchUrlProtectionBypassRequestBody2ToJSON(
  patchUrlProtectionBypassRequestBody2: PatchUrlProtectionBypassRequestBody2,
): string {
  return JSON.stringify(
    PatchUrlProtectionBypassRequestBody2$outboundSchema.parse(
      patchUrlProtectionBypassRequestBody2,
    ),
  );
}

/** @internal */
export type RequestBodyRevoke$Outbound = {
  secret: string;
  regenerate: boolean;
};

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

export function requestBodyRevokeToJSON(
  requestBodyRevoke: RequestBodyRevoke,
): string {
  return JSON.stringify(
    RequestBodyRevoke$outboundSchema.parse(requestBodyRevoke),
  );
}

/** @internal */
export type PatchUrlProtectionBypassRequestBody1$Outbound = {
  ttl?: number | undefined;
  revoke?: RequestBodyRevoke$Outbound | undefined;
};

/** @internal */
export const PatchUrlProtectionBypassRequestBody1$outboundSchema: z.ZodType<
  PatchUrlProtectionBypassRequestBody1$Outbound,
  z.ZodTypeDef,
  PatchUrlProtectionBypassRequestBody1
> = z.object({
  ttl: z.number().optional(),
  revoke: z.lazy(() => RequestBodyRevoke$outboundSchema).optional(),
});

export function patchUrlProtectionBypassRequestBody1ToJSON(
  patchUrlProtectionBypassRequestBody1: PatchUrlProtectionBypassRequestBody1,
): string {
  return JSON.stringify(
    PatchUrlProtectionBypassRequestBody1$outboundSchema.parse(
      patchUrlProtectionBypassRequestBody1,
    ),
  );
}

/** @internal */
export type PatchUrlProtectionBypassRequestBody$Outbound =
  | PatchUrlProtectionBypassRequestBody2$Outbound
  | PatchUrlProtectionBypassRequestBody3$Outbound
  | PatchUrlProtectionBypassRequestBody1$Outbound;

/** @internal */
export const PatchUrlProtectionBypassRequestBody$outboundSchema: z.ZodType<
  PatchUrlProtectionBypassRequestBody$Outbound,
  z.ZodTypeDef,
  PatchUrlProtectionBypassRequestBody
> = smartUnion([
  z.lazy(() => PatchUrlProtectionBypassRequestBody2$outboundSchema),
  z.lazy(() => PatchUrlProtectionBypassRequestBody3$outboundSchema),
  z.lazy(() => PatchUrlProtectionBypassRequestBody1$outboundSchema),
]);

export function patchUrlProtectionBypassRequestBodyToJSON(
  patchUrlProtectionBypassRequestBody: PatchUrlProtectionBypassRequestBody,
): string {
  return JSON.stringify(
    PatchUrlProtectionBypassRequestBody$outboundSchema.parse(
      patchUrlProtectionBypassRequestBody,
    ),
  );
}

/** @internal */
export type PatchUrlProtectionBypassRequest$Outbound = {
  id: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?:
    | PatchUrlProtectionBypassRequestBody2$Outbound
    | PatchUrlProtectionBypassRequestBody3$Outbound
    | PatchUrlProtectionBypassRequestBody1$Outbound
    | undefined;
};

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

export function patchUrlProtectionBypassRequestToJSON(
  patchUrlProtectionBypassRequest: PatchUrlProtectionBypassRequest,
): string {
  return JSON.stringify(
    PatchUrlProtectionBypassRequest$outboundSchema.parse(
      patchUrlProtectionBypassRequest,
    ),
  );
}
