/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { Meta, Meta$inboundSchema } from "./meta.js";
import { Permission, Permission$inboundSchema } from "./permission.js";

export type V2KeysAddPermissionsResponseBody = {
  /**
   * Metadata object included in every API response. This provides context about the request and is essential for debugging, audit trails, and support inquiries. The `requestId` is particularly important when troubleshooting issues with the Unkey support team.
   */
  meta: Meta;
  /**
   * Complete list of all permissions directly assigned to the key (including both newly added permissions and those that were already assigned).
   *
   * @remarks
   *
   * This response includes:
   * - All direct permissions assigned to the key (both pre-existing and newly added)
   * - Both the permission ID and name for each permission
   *
   * Important notes:
   * - This list does NOT include permissions granted through roles
   * - For a complete permission picture, use `/v2/keys.getKey` instead
   * - An empty array indicates the key has no direct permissions assigned
   */
  data: Array<Permission>;
};

/** @internal */
export const V2KeysAddPermissionsResponseBody$inboundSchema: z.ZodType<
  V2KeysAddPermissionsResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  meta: Meta$inboundSchema,
  data: z.array(Permission$inboundSchema),
});

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