// Generated by bynkc — do not edit by hand.
// commons commerce.money

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "../runtime.js";

/**
 * Money commons. Represents currency amounts as minor units paired with
 * ISO-4217 currency codes.
 */

export type CurrencyCode = string & { readonly __brand: "CurrencyCode" };

export const CurrencyCode = {
  of(value: string): Result<CurrencyCode, ValidationError> {
    if (!new RegExp("^" + "[A-Z]{3}" + "$").test(value)) {
      return Err({ field: "CurrencyCode", message: "must match /[A-Z]{3}/", value });
    }
    return Ok(value as CurrencyCode);
  },
  unsafe(value: string): CurrencyCode {
    return value as CurrencyCode;
  },
};

/**
 * A monetary amount paired with its currency.
 */
export interface Money {
  readonly minorUnits: number;
  readonly currency: CurrencyCode;
}

export const Money = {
};

export type MoneyError =
    { readonly tag: "CurrencyMismatch" }
  | { readonly tag: "InsufficientFunds" };

export const MoneyError = {
  CurrencyMismatch: { tag: "CurrencyMismatch" } as MoneyError,
  InsufficientFunds: { tag: "InsufficientFunds" } as MoneyError,
};

