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

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.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 GetIntegrationResourcesRequest = {
  integrationConfigurationId: string;
};

/**
 * The current status of the resource
 */
export const GetIntegrationResourcesStatus = {
  Error: "error",
  Onboarding: "onboarding",
  Pending: "pending",
  Ready: "ready",
  Resumed: "resumed",
  Suspended: "suspended",
  Uninstalled: "uninstalled",
} as const;
/**
 * The current status of the resource
 */
export type GetIntegrationResourcesStatus = ClosedEnum<
  typeof GetIntegrationResourcesStatus
>;

export type GetIntegrationResourcesExperimentation = {
  edgeConfigSyncingEnabled?: boolean | undefined;
  edgeConfigId?: string | undefined;
  edgeConfigTokenId?: string | undefined;
};

/**
 * Any settings provided for the resource to support its product's protocols
 */
export type GetIntegrationResourcesProtocolSettings = {
  experimentation?: GetIntegrationResourcesExperimentation | undefined;
};

export const GetIntegrationResourcesLevel = {
  Error: "error",
  Info: "info",
  Warn: "warn",
} as const;
export type GetIntegrationResourcesLevel = ClosedEnum<
  typeof GetIntegrationResourcesLevel
>;

/**
 * The notification, if set, displayed to the user when viewing the resource in Vercel
 */
export type GetIntegrationResourcesNotification = {
  level: GetIntegrationResourcesLevel;
  title: string;
  message?: string | undefined;
  href?: string | undefined;
};

export type GetIntegrationResourcesMetadata =
  | string
  | number
  | Array<string>
  | Array<number>
  | boolean;

export type GetIntegrationResourcesResources = {
  /**
   * The ID provided by the partner for the given resource
   */
  partnerId: string;
  /**
   * The ID assigned by Vercel for the given resource
   */
  internalId: string;
  /**
   * The name of the resource as it is recorded in Vercel
   */
  name: string;
  /**
   * The current status of the resource
   */
  status?: GetIntegrationResourcesStatus | undefined;
  /**
   * The ID of the product the resource is derived from
   */
  productId: string;
  /**
   * Any settings provided for the resource to support its product's protocols
   */
  protocolSettings?: GetIntegrationResourcesProtocolSettings | undefined;
  /**
   * The notification, if set, displayed to the user when viewing the resource in Vercel
   */
  notification?: GetIntegrationResourcesNotification | undefined;
  /**
   * The ID of the billing plan the resource is subscribed to, if applicable
   */
  billingPlanId?: string | undefined;
  /**
   * The configured metadata for the resource as defined by its product's Metadata Schema
   */
  metadata?: {
    [k: string]: string | number | Array<string> | Array<number> | boolean;
  } | undefined;
};

export type GetIntegrationResourcesResponseBody = {
  resources: Array<GetIntegrationResourcesResources>;
};

/** @internal */
export type GetIntegrationResourcesRequest$Outbound = {
  integrationConfigurationId: string;
};

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

export function getIntegrationResourcesRequestToJSON(
  getIntegrationResourcesRequest: GetIntegrationResourcesRequest,
): string {
  return JSON.stringify(
    GetIntegrationResourcesRequest$outboundSchema.parse(
      getIntegrationResourcesRequest,
    ),
  );
}

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

/** @internal */
export const GetIntegrationResourcesExperimentation$inboundSchema: z.ZodType<
  GetIntegrationResourcesExperimentation,
  z.ZodTypeDef,
  unknown
> = z.object({
  edgeConfigSyncingEnabled: types.optional(types.boolean()),
  edgeConfigId: types.optional(types.string()),
  edgeConfigTokenId: types.optional(types.string()),
});

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

/** @internal */
export const GetIntegrationResourcesProtocolSettings$inboundSchema: z.ZodType<
  GetIntegrationResourcesProtocolSettings,
  z.ZodTypeDef,
  unknown
> = z.object({
  experimentation: types.optional(
    z.lazy(() => GetIntegrationResourcesExperimentation$inboundSchema),
  ),
});

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

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

/** @internal */
export const GetIntegrationResourcesNotification$inboundSchema: z.ZodType<
  GetIntegrationResourcesNotification,
  z.ZodTypeDef,
  unknown
> = z.object({
  level: GetIntegrationResourcesLevel$inboundSchema,
  title: types.string(),
  message: types.optional(types.string()),
  href: types.optional(types.string()),
});

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

/** @internal */
export const GetIntegrationResourcesMetadata$inboundSchema: z.ZodType<
  GetIntegrationResourcesMetadata,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  types.string(),
  types.number(),
  z.array(types.string()),
  z.array(types.number()),
  types.boolean(),
]);

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

/** @internal */
export const GetIntegrationResourcesResources$inboundSchema: z.ZodType<
  GetIntegrationResourcesResources,
  z.ZodTypeDef,
  unknown
> = z.object({
  partnerId: types.string(),
  internalId: types.string(),
  name: types.string(),
  status: types.optional(GetIntegrationResourcesStatus$inboundSchema),
  productId: types.string(),
  protocolSettings: types.optional(
    z.lazy(() => GetIntegrationResourcesProtocolSettings$inboundSchema),
  ),
  notification: types.optional(
    z.lazy(() => GetIntegrationResourcesNotification$inboundSchema),
  ),
  billingPlanId: types.optional(types.string()),
  metadata: types.optional(
    z.record(
      smartUnion([
        types.string(),
        types.number(),
        z.array(types.string()),
        z.array(types.number()),
        types.boolean(),
      ]),
    ),
  ),
});

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

/** @internal */
export const GetIntegrationResourcesResponseBody$inboundSchema: z.ZodType<
  GetIntegrationResourcesResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  resources: z.array(
    z.lazy(() => GetIntegrationResourcesResources$inboundSchema),
  ),
});

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