/*
 * 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 * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export const Ownership = {
  Owned: "owned",
  Linked: "linked",
  Sandbox: "sandbox",
} as const;
export type Ownership = ClosedEnum<typeof Ownership>;

export const ImportResourceStatus = {
  Ready: "ready",
  Pending: "pending",
  Onboarding: "onboarding",
  Suspended: "suspended",
  Resumed: "resumed",
  Uninstalled: "uninstalled",
  Error: "error",
} as const;
export type ImportResourceStatus = ClosedEnum<typeof ImportResourceStatus>;

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

export type ImportResourceDetails = {
  label: string;
  value?: string | undefined;
};

export type ImportResourceHighlightedDetails = {
  label: string;
  value?: string | undefined;
};

export type ImportResourceBillingPlan = {
  id: string;
  type: ImportResourceType;
  name: string;
  description?: string | undefined;
  paymentMethodRequired?: boolean | undefined;
  cost?: string | undefined;
  details?: Array<ImportResourceDetails> | undefined;
  highlightedDetails?: Array<ImportResourceHighlightedDetails> | undefined;
  effectiveDate?: string | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

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

export type ImportResourceNotification = {
  level: ImportResourceLevel;
  title: string;
  message?: string | undefined;
  href?: string | undefined;
};

/**
 * A map of environments to override values for the secret, used for setting different values across deployments in production, preview, and development environments. Note: the same value will be used for all deployments in the given environment.
 */
export type EnvironmentOverrides = {
  /**
   * Value used for development environment.
   */
  development?: string | undefined;
  /**
   * Value used for preview environment.
   */
  preview?: string | undefined;
  /**
   * Value used for production environment.
   */
  production?: string | undefined;
};

export type ImportResourceSecrets = {
  name: string;
  value: string;
  prefix?: string | undefined;
  /**
   * A map of environments to override values for the secret, used for setting different values across deployments in production, preview, and development environments. Note: the same value will be used for all deployments in the given environment.
   */
  environmentOverrides?: EnvironmentOverrides | undefined;
};

export type ImportResourceRequestBody = {
  ownership?: Ownership | undefined;
  productId: string;
  name: string;
  status: ImportResourceStatus;
  metadata?: { [k: string]: any } | undefined;
  billingPlan?: ImportResourceBillingPlan | undefined;
  notification?: ImportResourceNotification | undefined;
  extras?: { [k: string]: any } | undefined;
  secrets?: Array<ImportResourceSecrets> | undefined;
};

export type ImportResourceRequest = {
  integrationConfigurationId: string;
  resourceId: string;
  requestBody?: ImportResourceRequestBody | undefined;
};

export type ImportResourceResponseBody = {
  name: string;
};

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

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

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

/** @internal */
export type ImportResourceDetails$Outbound = {
  label: string;
  value?: string | undefined;
};

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

export function importResourceDetailsToJSON(
  importResourceDetails: ImportResourceDetails,
): string {
  return JSON.stringify(
    ImportResourceDetails$outboundSchema.parse(importResourceDetails),
  );
}

/** @internal */
export type ImportResourceHighlightedDetails$Outbound = {
  label: string;
  value?: string | undefined;
};

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

export function importResourceHighlightedDetailsToJSON(
  importResourceHighlightedDetails: ImportResourceHighlightedDetails,
): string {
  return JSON.stringify(
    ImportResourceHighlightedDetails$outboundSchema.parse(
      importResourceHighlightedDetails,
    ),
  );
}

/** @internal */
export type ImportResourceBillingPlan$Outbound = {
  id: string;
  type: string;
  name: string;
  description?: string | undefined;
  paymentMethodRequired?: boolean | undefined;
  cost?: string | undefined;
  details?: Array<ImportResourceDetails$Outbound> | undefined;
  highlightedDetails?:
    | Array<ImportResourceHighlightedDetails$Outbound>
    | undefined;
  effectiveDate?: string | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const ImportResourceBillingPlan$outboundSchema: z.ZodType<
  ImportResourceBillingPlan$Outbound,
  z.ZodTypeDef,
  ImportResourceBillingPlan
> = z.object({
  id: z.string(),
  type: ImportResourceType$outboundSchema,
  name: z.string(),
  description: z.string().optional(),
  paymentMethodRequired: z.boolean().optional(),
  cost: z.string().optional(),
  details: z.array(z.lazy(() => ImportResourceDetails$outboundSchema))
    .optional(),
  highlightedDetails: z.array(
    z.lazy(() => ImportResourceHighlightedDetails$outboundSchema),
  ).optional(),
  effectiveDate: z.string().optional(),
  additionalProperties: z.record(z.any()).optional(),
}).transform((v) => {
  return {
    ...v.additionalProperties,
    ...remap$(v, {
      additionalProperties: null,
    }),
  };
});

export function importResourceBillingPlanToJSON(
  importResourceBillingPlan: ImportResourceBillingPlan,
): string {
  return JSON.stringify(
    ImportResourceBillingPlan$outboundSchema.parse(importResourceBillingPlan),
  );
}

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

/** @internal */
export type ImportResourceNotification$Outbound = {
  level: string;
  title: string;
  message?: string | undefined;
  href?: string | undefined;
};

/** @internal */
export const ImportResourceNotification$outboundSchema: z.ZodType<
  ImportResourceNotification$Outbound,
  z.ZodTypeDef,
  ImportResourceNotification
> = z.object({
  level: ImportResourceLevel$outboundSchema,
  title: z.string(),
  message: z.string().optional(),
  href: z.string().optional(),
});

export function importResourceNotificationToJSON(
  importResourceNotification: ImportResourceNotification,
): string {
  return JSON.stringify(
    ImportResourceNotification$outboundSchema.parse(importResourceNotification),
  );
}

/** @internal */
export type EnvironmentOverrides$Outbound = {
  development?: string | undefined;
  preview?: string | undefined;
  production?: string | undefined;
};

/** @internal */
export const EnvironmentOverrides$outboundSchema: z.ZodType<
  EnvironmentOverrides$Outbound,
  z.ZodTypeDef,
  EnvironmentOverrides
> = z.object({
  development: z.string().optional(),
  preview: z.string().optional(),
  production: z.string().optional(),
});

export function environmentOverridesToJSON(
  environmentOverrides: EnvironmentOverrides,
): string {
  return JSON.stringify(
    EnvironmentOverrides$outboundSchema.parse(environmentOverrides),
  );
}

/** @internal */
export type ImportResourceSecrets$Outbound = {
  name: string;
  value: string;
  prefix?: string | undefined;
  environmentOverrides?: EnvironmentOverrides$Outbound | undefined;
};

/** @internal */
export const ImportResourceSecrets$outboundSchema: z.ZodType<
  ImportResourceSecrets$Outbound,
  z.ZodTypeDef,
  ImportResourceSecrets
> = z.object({
  name: z.string(),
  value: z.string(),
  prefix: z.string().optional(),
  environmentOverrides: z.lazy(() => EnvironmentOverrides$outboundSchema)
    .optional(),
});

export function importResourceSecretsToJSON(
  importResourceSecrets: ImportResourceSecrets,
): string {
  return JSON.stringify(
    ImportResourceSecrets$outboundSchema.parse(importResourceSecrets),
  );
}

/** @internal */
export type ImportResourceRequestBody$Outbound = {
  ownership?: string | undefined;
  productId: string;
  name: string;
  status: string;
  metadata?: { [k: string]: any } | undefined;
  billingPlan?: ImportResourceBillingPlan$Outbound | undefined;
  notification?: ImportResourceNotification$Outbound | undefined;
  extras?: { [k: string]: any } | undefined;
  secrets?: Array<ImportResourceSecrets$Outbound> | undefined;
};

/** @internal */
export const ImportResourceRequestBody$outboundSchema: z.ZodType<
  ImportResourceRequestBody$Outbound,
  z.ZodTypeDef,
  ImportResourceRequestBody
> = z.object({
  ownership: Ownership$outboundSchema.optional(),
  productId: z.string(),
  name: z.string(),
  status: ImportResourceStatus$outboundSchema,
  metadata: z.record(z.any()).optional(),
  billingPlan: z.lazy(() => ImportResourceBillingPlan$outboundSchema)
    .optional(),
  notification: z.lazy(() => ImportResourceNotification$outboundSchema)
    .optional(),
  extras: z.record(z.any()).optional(),
  secrets: z.array(z.lazy(() => ImportResourceSecrets$outboundSchema))
    .optional(),
});

export function importResourceRequestBodyToJSON(
  importResourceRequestBody: ImportResourceRequestBody,
): string {
  return JSON.stringify(
    ImportResourceRequestBody$outboundSchema.parse(importResourceRequestBody),
  );
}

/** @internal */
export type ImportResourceRequest$Outbound = {
  integrationConfigurationId: string;
  resourceId: string;
  RequestBody?: ImportResourceRequestBody$Outbound | undefined;
};

/** @internal */
export const ImportResourceRequest$outboundSchema: z.ZodType<
  ImportResourceRequest$Outbound,
  z.ZodTypeDef,
  ImportResourceRequest
> = z.object({
  integrationConfigurationId: z.string(),
  resourceId: z.string(),
  requestBody: z.lazy(() => ImportResourceRequestBody$outboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function importResourceRequestToJSON(
  importResourceRequest: ImportResourceRequest,
): string {
  return JSON.stringify(
    ImportResourceRequest$outboundSchema.parse(importResourceRequest),
  );
}

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

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