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

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type BalanceCreditOrderMetadata = {
  orderId: string;
  productId?: string | undefined;
  subscriptionId?: string | undefined;
  amount: number;
  currency: string;
  taxAmount: number;
  taxState?: string | null | undefined;
  taxCountry?: string | null | undefined;
  fee: number;
  exchangeRate?: number | undefined;
};

/** @internal */
export const BalanceCreditOrderMetadata$inboundSchema: z.ZodMiniType<
  BalanceCreditOrderMetadata,
  unknown
> = z.pipe(
  z.object({
    order_id: z.string(),
    product_id: z.optional(z.string()),
    subscription_id: z.optional(z.string()),
    amount: z.int(),
    currency: z.string(),
    tax_amount: z.int(),
    tax_state: z.optional(z.nullable(z.string())),
    tax_country: z.optional(z.nullable(z.string())),
    fee: z.int(),
    exchange_rate: z.optional(z.number()),
  }),
  z.transform((v) => {
    return remap$(v, {
      "order_id": "orderId",
      "product_id": "productId",
      "subscription_id": "subscriptionId",
      "tax_amount": "taxAmount",
      "tax_state": "taxState",
      "tax_country": "taxCountry",
      "exchange_rate": "exchangeRate",
    });
  }),
);

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