// Generated by bynkc — do not edit by hand.
// context commerce.orders

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

import { CustomerId as __CommonsCustomerId, OrderId as __CommonsOrderId } from "./identifiers.js";
import { Money as __CommonsMoney } from "./money.js";

export type CustomerId = __CommonsCustomerId & { readonly __ctxBrand: "commerce.orders" };
export const CustomerId = {
  of(value: string): Result<CustomerId, ValidationError> { return __CommonsCustomerId.of(value) as unknown as Result<CustomerId, ValidationError>; },
  unsafe(value: string): CustomerId { return __CommonsCustomerId.unsafe(value) as unknown as CustomerId; },
};
export type Money = __CommonsMoney & { readonly __ctxBrand: "commerce.orders" };
export type OrderId = __CommonsOrderId & { readonly __ctxBrand: "commerce.orders" };
export const OrderId = {
  of(value: string): Result<OrderId, ValidationError> { return __CommonsOrderId.of(value) as unknown as Result<OrderId, ValidationError>; },
  unsafe(value: string): OrderId { return __CommonsOrderId.unsafe(value) as unknown as OrderId; },
};

/**
 * Orders context. Composes cart items, applies discounts, places orders.
 * Depends on commerce.payment for authorisation (v0.5+).
 */

export type OrderError =
    { readonly tag: "EmptyCart" }
  | { readonly tag: "TooManyItems" }
  | { readonly tag: "TotalExceedsLimit" };

export const OrderError = {
  EmptyCart: { tag: "EmptyCart" } as OrderError,
  TooManyItems: { tag: "TooManyItems" } as OrderError,
  TotalExceedsLimit: { tag: "TotalExceedsLimit" } as OrderError,
};

export type OrderStatus =
    { readonly tag: "Pending" }
  | { readonly tag: "Placed" }
  | { readonly tag: "Cancelled" };

export const OrderStatus = {
  Pending: { tag: "Pending" } as OrderStatus,
  Placed: { tag: "Placed" } as OrderStatus,
  Cancelled: { tag: "Cancelled" } as OrderStatus,
};

/**
 * An order record. Carries items, status, customer, and timestamps.
 */
export interface Order {
  readonly id: OrderId;
  readonly customer: CustomerId;
  readonly total: Money;
  readonly status: OrderStatus;
}

export const Order = {
};

