/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../lib/primitives.js";
import { safeParse } from "../lib/schemas.js";
import { Result as SafeParseResult } from "../types/fp.js";
import {
Amount,
Amount$inboundSchema,
Amount$Outbound,
Amount$outboundSchema,
} from "./amount.js";
import {
CoinIdentifier,
CoinIdentifier$inboundSchema,
CoinIdentifier$Outbound,
CoinIdentifier$outboundSchema,
} from "./coinidentifier.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
/**
* Coin contains its unique identifier and the amount it represents.
*/
export type Coin = {
/**
* CoinIdentifier uniquely identifies a Coin.
*/
coinIdentifier: CoinIdentifier;
/**
* Amount is some Value of a Currency. It is considered invalid to specify a Value without a Currency.
*/
amount: Amount;
};
/** @internal */
export const Coin$inboundSchema: z.ZodType<Coin, z.ZodTypeDef, unknown> = z
.object({
coin_identifier: CoinIdentifier$inboundSchema,
amount: Amount$inboundSchema,
}).transform((v) => {
return remap$(v, {
"coin_identifier": "coinIdentifier",
});
});
/** @internal */
export type Coin$Outbound = {
coin_identifier: CoinIdentifier$Outbound;
amount: Amount$Outbound;
};
/** @internal */
export const Coin$outboundSchema: z.ZodType<Coin$Outbound, z.ZodTypeDef, Coin> =
z.object({
coinIdentifier: CoinIdentifier$outboundSchema,
amount: Amount$outboundSchema,
}).transform((v) => {
return remap$(v, {
coinIdentifier: "coin_identifier",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Coin$ {
/** @deprecated use `Coin$inboundSchema` instead. */
export const inboundSchema = Coin$inboundSchema;
/** @deprecated use `Coin$outboundSchema` instead. */
export const outboundSchema = Coin$outboundSchema;
/** @deprecated use `Coin$Outbound` instead. */
export type Outbound = Coin$Outbound;
}
export function coinToJSON(coin: Coin): string {
return JSON.stringify(Coin$outboundSchema.parse(coin));
}
export function coinFromJSON(
jsonString: string,
): SafeParseResult<Coin, SDKValidationError> {
return safeParse(
jsonString,
(x) => Coin$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Coin' from JSON`,
);
}