/*
 * 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 BalanceOrderMetadata = {
  transactionId: string;
  orderId: string;
  productId?: string | undefined;
  subscriptionId?: string | undefined;
  amount: number;
  netAmount?: number | undefined;
  currency: string;
  presentmentAmount: number;
  presentmentCurrency: string;
  taxAmount: number;
  taxState?: string | null | undefined;
  taxCountry?: string | null | undefined;
  fee: number;
  exchangeRate?: number | undefined;
};

/** @internal */
export const BalanceOrderMetadata$inboundSchema: z.ZodMiniType<
  BalanceOrderMetadata,
  unknown
> = z.pipe(
  z.object({
    transaction_id: z.string(),
    order_id: z.string(),
    product_id: z.optional(z.string()),
    subscription_id: z.optional(z.string()),
    amount: z.int(),
    net_amount: z.optional(z.int()),
    currency: z.string(),
    presentment_amount: z.int(),
    presentment_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, {
      "transaction_id": "transactionId",
      "order_id": "orderId",
      "product_id": "productId",
      "subscription_id": "subscriptionId",
      "net_amount": "netAmount",
      "presentment_amount": "presentmentAmount",
      "presentment_currency": "presentmentCurrency",
      "tax_amount": "taxAmount",
      "tax_state": "taxState",
      "tax_country": "taxCountry",
      "exchange_rate": "exchangeRate",
    });
  }),
);

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