/*
 * 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 GetConfigurationRequest = {
  /**
   * ID of the configuration to check
   */
  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;
};

/**
 * The configuration status. Optional. If not defined, assume 'ready'.
 */
export const GetConfigurationResponseBodyIntegrationsResponseStatus = {
  Error: "error",
  Onboarding: "onboarding",
  Pending: "pending",
  Ready: "ready",
  Resumed: "resumed",
  Suspended: "suspended",
  Uninstalled: "uninstalled",
} as const;
/**
 * The configuration status. Optional. If not defined, assume 'ready'.
 */
export type GetConfigurationResponseBodyIntegrationsResponseStatus = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsResponseStatus
>;

/**
 * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
 */
export const GetConfigurationResponseBodyIntegrationsResponseSource = {
  Backoffice: "backoffice",
  Cli: "cli",
  DeployButton: "deploy-button",
  External: "external",
  Marketplace: "marketplace",
  Oauth: "oauth",
  ResourceClaims: "resource-claims",
  V0: "v0",
} as const;
/**
 * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
 */
export type GetConfigurationResponseBodyIntegrationsResponseSource = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsResponseSource
>;

export const GetConfigurationResponseBodyIntegrationsResponseType = {
  IntegrationConfiguration: "integration-configuration",
} as const;
export type GetConfigurationResponseBodyIntegrationsResponseType = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsResponseType
>;

export const GetConfigurationResponseBodyIntegrationsResponseDisabledReason = {
  AccountPlanDowngrade: "account-plan-downgrade",
  DisabledByAdmin: "disabled-by-admin",
  DisabledByOwner: "disabled-by-owner",
  FeatureNotAvailable: "feature-not-available",
  OriginalOwnerLeftTheTeam: "original-owner-left-the-team",
  OriginalOwnerRoleDowngraded: "original-owner-role-downgraded",
} as const;
export type GetConfigurationResponseBodyIntegrationsResponseDisabledReason =
  ClosedEnum<
    typeof GetConfigurationResponseBodyIntegrationsResponseDisabledReason
  >;

/**
 * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
 */
export const GetConfigurationResponseBodyIntegrationsResponseInstallationType =
  {
    External: "external",
    Marketplace: "marketplace",
  } as const;
/**
 * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
 */
export type GetConfigurationResponseBodyIntegrationsResponseInstallationType =
  ClosedEnum<
    typeof GetConfigurationResponseBodyIntegrationsResponseInstallationType
  >;

/**
 * A configuration represents information about a single installation of an integration within an individual or team account
 */
export type GetConfigurationResponseBody3 = {
  /**
   * A timestamp that tells you when the configuration was installed successfully
   */
  completedAt?: number | undefined;
  /**
   * A timestamp that tells you when the configuration was created
   */
  createdAt?: number | undefined;
  /**
   * The unique identifier of the configuration
   */
  id?: string | undefined;
  /**
   * The unique identifier of the app the configuration was created for
   */
  integrationId?: string | undefined;
  /**
   * The user or team ID that owns the configuration
   */
  ownerId?: string | undefined;
  /**
   * The configuration status. Optional. If not defined, assume 'ready'.
   */
  status?: GetConfigurationResponseBodyIntegrationsResponseStatus | undefined;
  /**
   * An external identifier defined by the integration vendor.
   */
  externalId?: string | undefined;
  /**
   * When a configuration is limited to access certain projects, this will contain each of the project ID it is allowed to access. If it is not defined, the configuration has full access.
   */
  projects?: Array<string> | undefined;
  /**
   * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
   */
  source?: GetConfigurationResponseBodyIntegrationsResponseSource | undefined;
  /**
   * The slug of the integration the configuration is created for.
   */
  slug?: string | undefined;
  /**
   * When the configuration was created for a team, this will show the ID of the team.
   */
  teamId?: string | null | undefined;
  type?: GetConfigurationResponseBodyIntegrationsResponseType | undefined;
  /**
   * A timestamp that tells you when the configuration was updated.
   */
  updatedAt?: number | undefined;
  /**
   * The ID of the user that created the configuration.
   */
  userId?: string | undefined;
  /**
   * The resources that are allowed to be accessed by the configuration.
   */
  scopes?: Array<string> | undefined;
  /**
   * A timestamp that tells you when the configuration was disabled. Note: Configurations can be disabled when the associated user loses access to a team. They do not function during this time until the configuration is 'transferred', meaning the associated user is changed to one with access to the team.
   */
  disabledAt?: number | undefined;
  /**
   * A timestamp that tells you when the configuration was deleted.
   */
  deletedAt?: number | null | undefined;
  /**
   * A timestamp that tells you when the configuration deletion has been started for cases when the deletion needs to be settled/approved by partners, such as when marketplace invoices have been paid.
   */
  deleteRequestedAt?: number | null | undefined;
  /**
   * Record when the customer initited deletion, independent of whether `deleteRequestedAt` gets set.
   */
  customerDeleteRequestedAt?: number | null | undefined;
  disabledReason?:
    | GetConfigurationResponseBodyIntegrationsResponseDisabledReason
    | undefined;
  /**
   * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
   */
  installationType?:
    | GetConfigurationResponseBodyIntegrationsResponseInstallationType
    | undefined;
};

/**
 * The configuration status. Optional. If not defined, assume 'ready'.
 */
export const GetConfigurationResponseBodyIntegrationsStatus = {
  Error: "error",
  Onboarding: "onboarding",
  Pending: "pending",
  Ready: "ready",
  Resumed: "resumed",
  Suspended: "suspended",
  Uninstalled: "uninstalled",
} as const;
/**
 * The configuration status. Optional. If not defined, assume 'ready'.
 */
export type GetConfigurationResponseBodyIntegrationsStatus = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsStatus
>;

/**
 * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
 */
export const GetConfigurationResponseBodyIntegrationsSource = {
  Backoffice: "backoffice",
  Cli: "cli",
  DeployButton: "deploy-button",
  External: "external",
  Marketplace: "marketplace",
  Oauth: "oauth",
  ResourceClaims: "resource-claims",
  V0: "v0",
} as const;
/**
 * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
 */
export type GetConfigurationResponseBodyIntegrationsSource = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsSource
>;

export const GetConfigurationResponseBodyIntegrationsType = {
  IntegrationConfiguration: "integration-configuration",
} as const;
export type GetConfigurationResponseBodyIntegrationsType = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsType
>;

export const GetConfigurationResponseBodyIntegrationsDisabledReason = {
  AccountPlanDowngrade: "account-plan-downgrade",
  DisabledByAdmin: "disabled-by-admin",
  DisabledByOwner: "disabled-by-owner",
  FeatureNotAvailable: "feature-not-available",
  OriginalOwnerLeftTheTeam: "original-owner-left-the-team",
  OriginalOwnerRoleDowngraded: "original-owner-role-downgraded",
} as const;
export type GetConfigurationResponseBodyIntegrationsDisabledReason = ClosedEnum<
  typeof GetConfigurationResponseBodyIntegrationsDisabledReason
>;

/**
 * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
 */
export const GetConfigurationResponseBodyIntegrationsInstallationType = {
  External: "external",
  Marketplace: "marketplace",
} as const;
/**
 * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
 */
export type GetConfigurationResponseBodyIntegrationsInstallationType =
  ClosedEnum<typeof GetConfigurationResponseBodyIntegrationsInstallationType>;

/**
 * The configuration with the provided id
 */
export type GetConfigurationResponseBody2 = {
  /**
   * A timestamp that tells you when the configuration was installed successfully
   */
  completedAt?: number | undefined;
  /**
   * A timestamp that tells you when the configuration was created
   */
  createdAt: number;
  /**
   * The unique identifier of the configuration
   */
  id: string;
  /**
   * The unique identifier of the app the configuration was created for
   */
  integrationId: string;
  /**
   * The user or team ID that owns the configuration
   */
  ownerId: string;
  /**
   * The configuration status. Optional. If not defined, assume 'ready'.
   */
  status?: GetConfigurationResponseBodyIntegrationsStatus | undefined;
  /**
   * An external identifier defined by the integration vendor.
   */
  externalId?: string | undefined;
  /**
   * When a configuration is limited to access certain projects, this will contain each of the project ID it is allowed to access. If it is not defined, the configuration has full access.
   */
  projects?: Array<string> | undefined;
  /**
   * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
   */
  source?: GetConfigurationResponseBodyIntegrationsSource | undefined;
  /**
   * The slug of the integration the configuration is created for.
   */
  slug: string;
  /**
   * When the configuration was created for a team, this will show the ID of the team.
   */
  teamId?: string | null | undefined;
  type: GetConfigurationResponseBodyIntegrationsType;
  /**
   * A timestamp that tells you when the configuration was updated.
   */
  updatedAt: number;
  /**
   * The ID of the user that created the configuration.
   */
  userId: string;
  /**
   * The resources that are allowed to be accessed by the configuration.
   */
  scopes: Array<string>;
  /**
   * A timestamp that tells you when the configuration was disabled. Note: Configurations can be disabled when the associated user loses access to a team. They do not function during this time until the configuration is 'transferred', meaning the associated user is changed to one with access to the team.
   */
  disabledAt?: number | undefined;
  /**
   * A timestamp that tells you when the configuration was deleted.
   */
  deletedAt?: number | null | undefined;
  /**
   * A timestamp that tells you when the configuration deletion has been started for cases when the deletion needs to be settled/approved by partners, such as when marketplace invoices have been paid.
   */
  deleteRequestedAt?: number | null | undefined;
  /**
   * Record when the customer initited deletion, independent of whether `deleteRequestedAt` gets set.
   */
  customerDeleteRequestedAt?: number | null | undefined;
  disabledReason?:
    | GetConfigurationResponseBodyIntegrationsDisabledReason
    | undefined;
  /**
   * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
   */
  installationType?:
    | GetConfigurationResponseBodyIntegrationsInstallationType
    | undefined;
};

/**
 * A string representing the permission for projects. Possible values are `all` or `selected`.
 */
export const ProjectSelection = {
  All: "all",
  Selected: "selected",
} as const;
/**
 * A string representing the permission for projects. Possible values are `all` or `selected`.
 */
export type ProjectSelection = ClosedEnum<typeof ProjectSelection>;

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

export type ResponseBodyNotification = {
  level: GetConfigurationResponseBodyLevel;
  title: string;
  message?: string | undefined;
  href?: string | undefined;
};

export type TransferRequestRequester = {
  name: string;
  email?: string | undefined;
};

export type TransferRequest2 = {
  kind: "transfer-from-marketplace";
  requestId: string;
  transferId: string;
  requester: TransferRequestRequester;
  createdAt: number;
  expiresAt: number;
  discardedAt?: number | undefined;
  discardedBy?: string | undefined;
  approvedAt?: number | undefined;
  approvedBy?: string | undefined;
  authorizationId?: string | undefined;
};

export const TransferRequestType = {
  Prepayment: "prepayment",
  Subscription: "subscription",
} as const;
export type TransferRequestType = ClosedEnum<typeof TransferRequestType>;

export const TransferRequestScope = {
  Installation: "installation",
  Resource: "resource",
} as const;
export type TransferRequestScope = ClosedEnum<typeof TransferRequestScope>;

export type TransferRequestBillingPlan = {
  id: string;
  type: TransferRequestType;
  scope?: TransferRequestScope | undefined;
  name: string;
  description: string;
  paymentMethodRequired?: boolean | undefined;
  preauthorizationAmount?: number | undefined;
};

export type Requester = {
  name: string;
  email?: string | undefined;
};

export type TransferRequest1 = {
  kind: "transfer-to-marketplace";
  metadata?: { [k: string]: any } | undefined;
  billingPlan?: TransferRequestBillingPlan | undefined;
  requestId: string;
  transferId: string;
  requester: Requester;
  createdAt: number;
  expiresAt: number;
  discardedAt?: number | undefined;
  discardedBy?: string | undefined;
  approvedAt?: number | undefined;
  approvedBy?: string | undefined;
  authorizationId?: string | undefined;
};

export type TransferRequest = TransferRequest1 | TransferRequest2;

/**
 * The configuration status. Optional. If not defined, assume 'ready'.
 */
export const GetConfigurationResponseBodyStatus = {
  Error: "error",
  Onboarding: "onboarding",
  Pending: "pending",
  Ready: "ready",
  Resumed: "resumed",
  Suspended: "suspended",
  Uninstalled: "uninstalled",
} as const;
/**
 * The configuration status. Optional. If not defined, assume 'ready'.
 */
export type GetConfigurationResponseBodyStatus = ClosedEnum<
  typeof GetConfigurationResponseBodyStatus
>;

export const GetConfigurationResponseBodyType = {
  IntegrationConfiguration: "integration-configuration",
} as const;
export type GetConfigurationResponseBodyType = ClosedEnum<
  typeof GetConfigurationResponseBodyType
>;

/**
 * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
 */
export const GetConfigurationResponseBodySource = {
  Backoffice: "backoffice",
  Cli: "cli",
  DeployButton: "deploy-button",
  External: "external",
  Marketplace: "marketplace",
  Oauth: "oauth",
  ResourceClaims: "resource-claims",
  V0: "v0",
} as const;
/**
 * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
 */
export type GetConfigurationResponseBodySource = ClosedEnum<
  typeof GetConfigurationResponseBodySource
>;

export const GetConfigurationResponseBodyDisabledReason = {
  AccountPlanDowngrade: "account-plan-downgrade",
  DisabledByAdmin: "disabled-by-admin",
  DisabledByOwner: "disabled-by-owner",
  FeatureNotAvailable: "feature-not-available",
  OriginalOwnerLeftTheTeam: "original-owner-left-the-team",
  OriginalOwnerRoleDowngraded: "original-owner-role-downgraded",
} as const;
export type GetConfigurationResponseBodyDisabledReason = ClosedEnum<
  typeof GetConfigurationResponseBodyDisabledReason
>;

/**
 * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
 */
export const GetConfigurationResponseBodyInstallationType = {
  External: "external",
  Marketplace: "marketplace",
} as const;
/**
 * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
 */
export type GetConfigurationResponseBodyInstallationType = ClosedEnum<
  typeof GetConfigurationResponseBodyInstallationType
>;

export type GetConfigurationResponseBody1 = {
  /**
   * A string representing the permission for projects. Possible values are `all` or `selected`.
   */
  projectSelection: ProjectSelection;
  notification: ResponseBodyNotification;
  transferRequest: TransferRequest1 | TransferRequest2;
  /**
   * When a configuration is limited to access certain projects, this will contain each of the project ID it is allowed to access. If it is not defined, the configuration has full access.
   */
  projects?: Array<string> | undefined;
  /**
   * The configuration status. Optional. If not defined, assume 'ready'.
   */
  status?: GetConfigurationResponseBodyStatus | undefined;
  type: GetConfigurationResponseBodyType;
  /**
   * The unique identifier of the configuration
   */
  id: string;
  /**
   * The unique identifier of the app the configuration was created for
   */
  integrationId: string;
  /**
   * The ID of the user that created the configuration.
   */
  userId: string;
  /**
   * The user or team ID that owns the configuration
   */
  ownerId: string;
  /**
   * A timestamp that tells you when the configuration was created
   */
  createdAt: number;
  /**
   * A timestamp that tells you when the configuration was updated.
   */
  updatedAt: number;
  /**
   * A timestamp that tells you when the configuration was deleted.
   */
  deletedAt?: number | null | undefined;
  canConfigureOpenTelemetry?: boolean | undefined;
  /**
   * A timestamp that tells you when the configuration was installed successfully
   */
  completedAt?: number | undefined;
  /**
   * An external identifier defined by the integration vendor.
   */
  externalId?: string | undefined;
  /**
   * Source defines where the configuration was installed from. It is used to analyze user engagement for integration installations in product metrics.
   */
  source?: GetConfigurationResponseBodySource | undefined;
  /**
   * The slug of the integration the configuration is created for.
   */
  slug: string;
  /**
   * When the configuration was created for a team, this will show the ID of the team.
   */
  teamId?: string | null | undefined;
  /**
   * The resources that are allowed to be accessed by the configuration.
   */
  scopes: Array<string>;
  /**
   * A timestamp that tells you when the configuration was disabled. Note: Configurations can be disabled when the associated user loses access to a team. They do not function during this time until the configuration is 'transferred', meaning the associated user is changed to one with access to the team.
   */
  disabledAt?: number | undefined;
  /**
   * A timestamp that tells you when the configuration deletion has been started for cases when the deletion needs to be settled/approved by partners, such as when marketplace invoices have been paid.
   */
  deleteRequestedAt?: number | null | undefined;
  /**
   * Record when the customer initited deletion, independent of whether `deleteRequestedAt` gets set.
   */
  customerDeleteRequestedAt?: number | null | undefined;
  disabledReason?: GetConfigurationResponseBodyDisabledReason | undefined;
  /**
   * Defines the installation type. - 'external' integrations are installed via the existing integrations flow - 'marketplace' integrations are natively installed: - when accepting the TOS of a partner during the store creation process - if undefined, assume 'external'
   */
  installationType?: GetConfigurationResponseBodyInstallationType | undefined;
};

/**
 * The configuration with the provided id
 */
export type GetConfigurationResponseBody =
  | GetConfigurationResponseBody1
  | GetConfigurationResponseBody2
  | GetConfigurationResponseBody3;

/** @internal */
export type GetConfigurationRequest$Outbound = {
  id: string;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const GetConfigurationRequest$outboundSchema: z.ZodType<
  GetConfigurationRequest$Outbound,
  z.ZodTypeDef,
  GetConfigurationRequest
> = z.object({
  id: z.string(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function getConfigurationRequestToJSON(
  getConfigurationRequest: GetConfigurationRequest,
): string {
  return JSON.stringify(
    GetConfigurationRequest$outboundSchema.parse(getConfigurationRequest),
  );
}

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

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

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

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

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

/** @internal */
export const GetConfigurationResponseBody3$inboundSchema: z.ZodType<
  GetConfigurationResponseBody3,
  z.ZodTypeDef,
  unknown
> = z.object({
  completedAt: types.optional(types.number()),
  createdAt: types.optional(types.number()),
  id: types.optional(types.string()),
  integrationId: types.optional(types.string()),
  ownerId: types.optional(types.string()),
  status: types.optional(
    GetConfigurationResponseBodyIntegrationsResponseStatus$inboundSchema,
  ),
  externalId: types.optional(types.string()),
  projects: types.optional(z.array(types.string())),
  source: types.optional(
    GetConfigurationResponseBodyIntegrationsResponseSource$inboundSchema,
  ),
  slug: types.optional(types.string()),
  teamId: z.nullable(types.string()).optional(),
  type: types.optional(
    GetConfigurationResponseBodyIntegrationsResponseType$inboundSchema,
  ),
  updatedAt: types.optional(types.number()),
  userId: types.optional(types.string()),
  scopes: types.optional(z.array(types.string())),
  disabledAt: types.optional(types.number()),
  deletedAt: z.nullable(types.number()).optional(),
  deleteRequestedAt: z.nullable(types.number()).optional(),
  customerDeleteRequestedAt: z.nullable(types.number()).optional(),
  disabledReason: types.optional(
    GetConfigurationResponseBodyIntegrationsResponseDisabledReason$inboundSchema,
  ),
  installationType: types.optional(
    GetConfigurationResponseBodyIntegrationsResponseInstallationType$inboundSchema,
  ),
});

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

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

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

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

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

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

/** @internal */
export const GetConfigurationResponseBody2$inboundSchema: z.ZodType<
  GetConfigurationResponseBody2,
  z.ZodTypeDef,
  unknown
> = z.object({
  completedAt: types.optional(types.number()),
  createdAt: types.number(),
  id: types.string(),
  integrationId: types.string(),
  ownerId: types.string(),
  status: types.optional(
    GetConfigurationResponseBodyIntegrationsStatus$inboundSchema,
  ),
  externalId: types.optional(types.string()),
  projects: types.optional(z.array(types.string())),
  source: types.optional(
    GetConfigurationResponseBodyIntegrationsSource$inboundSchema,
  ),
  slug: types.string(),
  teamId: z.nullable(types.string()).optional(),
  type: GetConfigurationResponseBodyIntegrationsType$inboundSchema,
  updatedAt: types.number(),
  userId: types.string(),
  scopes: z.array(types.string()),
  disabledAt: types.optional(types.number()),
  deletedAt: z.nullable(types.number()).optional(),
  deleteRequestedAt: z.nullable(types.number()).optional(),
  customerDeleteRequestedAt: z.nullable(types.number()).optional(),
  disabledReason: types.optional(
    GetConfigurationResponseBodyIntegrationsDisabledReason$inboundSchema,
  ),
  installationType: types.optional(
    GetConfigurationResponseBodyIntegrationsInstallationType$inboundSchema,
  ),
});

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

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

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

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

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

/** @internal */
export const TransferRequestRequester$inboundSchema: z.ZodType<
  TransferRequestRequester,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: types.string(),
  email: types.optional(types.string()),
});

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

/** @internal */
export const TransferRequest2$inboundSchema: z.ZodType<
  TransferRequest2,
  z.ZodTypeDef,
  unknown
> = z.object({
  kind: types.literal("transfer-from-marketplace"),
  requestId: types.string(),
  transferId: types.string(),
  requester: z.lazy(() => TransferRequestRequester$inboundSchema),
  createdAt: types.number(),
  expiresAt: types.number(),
  discardedAt: types.optional(types.number()),
  discardedBy: types.optional(types.string()),
  approvedAt: types.optional(types.number()),
  approvedBy: types.optional(types.string()),
  authorizationId: types.optional(types.string()),
});

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

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

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

/** @internal */
export const TransferRequestBillingPlan$inboundSchema: z.ZodType<
  TransferRequestBillingPlan,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  type: TransferRequestType$inboundSchema,
  scope: types.optional(TransferRequestScope$inboundSchema),
  name: types.string(),
  description: types.string(),
  paymentMethodRequired: types.optional(types.boolean()),
  preauthorizationAmount: types.optional(types.number()),
});

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

/** @internal */
export const Requester$inboundSchema: z.ZodType<
  Requester,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: types.string(),
  email: types.optional(types.string()),
});

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

/** @internal */
export const TransferRequest1$inboundSchema: z.ZodType<
  TransferRequest1,
  z.ZodTypeDef,
  unknown
> = z.object({
  kind: types.literal("transfer-to-marketplace"),
  metadata: types.optional(z.record(z.any())),
  billingPlan: types.optional(
    z.lazy(() => TransferRequestBillingPlan$inboundSchema),
  ),
  requestId: types.string(),
  transferId: types.string(),
  requester: z.lazy(() => Requester$inboundSchema),
  createdAt: types.number(),
  expiresAt: types.number(),
  discardedAt: types.optional(types.number()),
  discardedBy: types.optional(types.string()),
  approvedAt: types.optional(types.number()),
  approvedBy: types.optional(types.string()),
  authorizationId: types.optional(types.string()),
});

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

/** @internal */
export const TransferRequest$inboundSchema: z.ZodType<
  TransferRequest,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => TransferRequest1$inboundSchema),
  z.lazy(() => TransferRequest2$inboundSchema),
]);

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

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

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

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

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

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

/** @internal */
export const GetConfigurationResponseBody1$inboundSchema: z.ZodType<
  GetConfigurationResponseBody1,
  z.ZodTypeDef,
  unknown
> = z.object({
  projectSelection: ProjectSelection$inboundSchema,
  notification: z.lazy(() => ResponseBodyNotification$inboundSchema),
  transferRequest: z.union([
    z.lazy(() => TransferRequest1$inboundSchema),
    z.lazy(() => TransferRequest2$inboundSchema),
  ]),
  projects: types.optional(z.array(types.string())),
  status: types.optional(GetConfigurationResponseBodyStatus$inboundSchema),
  type: GetConfigurationResponseBodyType$inboundSchema,
  id: types.string(),
  integrationId: types.string(),
  userId: types.string(),
  ownerId: types.string(),
  createdAt: types.number(),
  updatedAt: types.number(),
  deletedAt: z.nullable(types.number()).optional(),
  canConfigureOpenTelemetry: types.optional(types.boolean()),
  completedAt: types.optional(types.number()),
  externalId: types.optional(types.string()),
  source: types.optional(GetConfigurationResponseBodySource$inboundSchema),
  slug: types.string(),
  teamId: z.nullable(types.string()).optional(),
  scopes: z.array(types.string()),
  disabledAt: types.optional(types.number()),
  deleteRequestedAt: z.nullable(types.number()).optional(),
  customerDeleteRequestedAt: z.nullable(types.number()).optional(),
  disabledReason: types.optional(
    GetConfigurationResponseBodyDisabledReason$inboundSchema,
  ),
  installationType: types.optional(
    GetConfigurationResponseBodyInstallationType$inboundSchema,
  ),
});

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

/** @internal */
export const GetConfigurationResponseBody$inboundSchema: z.ZodType<
  GetConfigurationResponseBody,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => GetConfigurationResponseBody1$inboundSchema),
  z.lazy(() => GetConfigurationResponseBody2$inboundSchema),
  z.lazy(() => GetConfigurationResponseBody3$inboundSchema),
]);

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