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

export const QueryParamSource = {
  Marketplace: "marketplace",
  DeployButton: "deploy-button",
  External: "external",
  V0: "v0",
  ResourceClaims: "resource-claims",
  Cli: "cli",
  Oauth: "oauth",
  Backoffice: "backoffice",
} as const;
export type QueryParamSource = ClosedEnum<typeof QueryParamSource>;

export type GetBillingPlansRequest = {
  integrationIdOrSlug: string;
  integrationConfigurationId?: string | undefined;
  productIdOrSlug: string;
  metadata?: string | undefined;
  source?: QueryParamSource | undefined;
  /**
   * 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;
};

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

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

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

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

export type Quote = {
  line: string;
  amount: string;
};

export type Plans = {
  type: GetBillingPlansType;
  id: string;
  name: string;
  scope: GetBillingPlansScope;
  description: string;
  paymentMethodRequired: boolean;
  preauthorizationAmount?: number | undefined;
  initialCharge?: string | undefined;
  minimumAmount?: string | undefined;
  maximumAmount?: string | undefined;
  maximumAmountAutoPurchasePerPeriod?: string | undefined;
  cost?: string | undefined;
  details?: Array<GetBillingPlansDetails> | undefined;
  highlightedDetails?: Array<GetBillingPlansHighlightedDetails> | undefined;
  quote?: Array<Quote> | undefined;
  effectiveDate?: string | undefined;
  disabled?: boolean | undefined;
};

export type GetBillingPlansResponseBody = {
  plans: Array<Plans>;
};

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

/** @internal */
export type GetBillingPlansRequest$Outbound = {
  integrationIdOrSlug: string;
  integrationConfigurationId?: string | undefined;
  productIdOrSlug: string;
  metadata?: string | undefined;
  source?: string | undefined;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const GetBillingPlansRequest$outboundSchema: z.ZodType<
  GetBillingPlansRequest$Outbound,
  z.ZodTypeDef,
  GetBillingPlansRequest
> = z.object({
  integrationIdOrSlug: z.string(),
  integrationConfigurationId: z.string().optional(),
  productIdOrSlug: z.string(),
  metadata: z.string().optional(),
  source: QueryParamSource$outboundSchema.optional(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function getBillingPlansRequestToJSON(
  getBillingPlansRequest: GetBillingPlansRequest,
): string {
  return JSON.stringify(
    GetBillingPlansRequest$outboundSchema.parse(getBillingPlansRequest),
  );
}

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

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

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

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

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

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

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

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

/** @internal */
export const Plans$inboundSchema: z.ZodType<Plans, z.ZodTypeDef, unknown> = z
  .object({
    type: GetBillingPlansType$inboundSchema,
    id: types.string(),
    name: types.string(),
    scope: GetBillingPlansScope$inboundSchema,
    description: types.string(),
    paymentMethodRequired: types.boolean(),
    preauthorizationAmount: types.optional(types.number()),
    initialCharge: types.optional(types.string()),
    minimumAmount: types.optional(types.string()),
    maximumAmount: types.optional(types.string()),
    maximumAmountAutoPurchasePerPeriod: types.optional(types.string()),
    cost: types.optional(types.string()),
    details: types.optional(
      z.array(z.lazy(() => GetBillingPlansDetails$inboundSchema)),
    ),
    highlightedDetails: types.optional(
      z.array(z.lazy(() => GetBillingPlansHighlightedDetails$inboundSchema)),
    ),
    quote: types.optional(z.array(z.lazy(() => Quote$inboundSchema))),
    effectiveDate: types.optional(types.string()),
    disabled: types.optional(types.boolean()),
  });

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

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

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