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

/**
 * Whether this statement should allow or deny actions on the resources.
 */
export const AiConfigsAccessAllowedReasonEffect = {
  Allow: "allow",
  Deny: "deny",
} as const;
/**
 * Whether this statement should allow or deny actions on the resources.
 */
export type AiConfigsAccessAllowedReasonEffect = ClosedEnum<
  typeof AiConfigsAccessAllowedReasonEffect
>;

export type AiConfigsAccessAllowedReason = {
  /**
   * Resource specifier strings
   */
  resources?: Array<string> | undefined;
  /**
   * Targeted resources are the resources NOT in this list. The <code>resources</code> and <code>notActions</code> fields must be empty to use this field.
   */
  notResources?: Array<string> | undefined;
  /**
   * Actions to perform on a resource
   */
  actions?: Array<string> | undefined;
  /**
   * Targeted actions are the actions NOT in this list. The <code>actions</code> and <code>notResources</code> fields must be empty to use this field.
   */
  notActions?: Array<string> | undefined;
  /**
   * Whether this statement should allow or deny actions on the resources.
   */
  effect: AiConfigsAccessAllowedReasonEffect;
  roleName?: string | undefined;
};

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

/** @internal */
export const AiConfigsAccessAllowedReason$inboundSchema: z.ZodType<
  AiConfigsAccessAllowedReason,
  z.ZodTypeDef,
  unknown
> = z.object({
  resources: z.array(z.string()).optional(),
  notResources: z.array(z.string()).optional(),
  actions: z.array(z.string()).optional(),
  notActions: z.array(z.string()).optional(),
  effect: AiConfigsAccessAllowedReasonEffect$inboundSchema,
  role_name: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    "role_name": "roleName",
  });
});
/** @internal */
export type AiConfigsAccessAllowedReason$Outbound = {
  resources?: Array<string> | undefined;
  notResources?: Array<string> | undefined;
  actions?: Array<string> | undefined;
  notActions?: Array<string> | undefined;
  effect: string;
  role_name?: string | undefined;
};

/** @internal */
export const AiConfigsAccessAllowedReason$outboundSchema: z.ZodType<
  AiConfigsAccessAllowedReason$Outbound,
  z.ZodTypeDef,
  AiConfigsAccessAllowedReason
> = z.object({
  resources: z.array(z.string()).optional(),
  notResources: z.array(z.string()).optional(),
  actions: z.array(z.string()).optional(),
  notActions: z.array(z.string()).optional(),
  effect: AiConfigsAccessAllowedReasonEffect$outboundSchema,
  roleName: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    roleName: "role_name",
  });
});

export function aiConfigsAccessAllowedReasonToJSON(
  aiConfigsAccessAllowedReason: AiConfigsAccessAllowedReason,
): string {
  return JSON.stringify(
    AiConfigsAccessAllowedReason$outboundSchema.parse(
      aiConfigsAccessAllowedReason,
    ),
  );
}
export function aiConfigsAccessAllowedReasonFromJSON(
  jsonString: string,
): SafeParseResult<AiConfigsAccessAllowedReason, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AiConfigsAccessAllowedReason$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AiConfigsAccessAllowedReason' from JSON`,
  );
}
