import type { ShippingAddress } from '../../shipping/index.js';
import type { OrderView } from '../../orders/index.js';

export interface CheckoutItem {
  variantId: string;
  quantity: number;
}

export interface CheckoutRequest {
  items?: never;
  itemsByVariant?: never;
  address: ShippingAddress;
  promoCode?: string | null;
  idempotencyKey: string;
}

export interface PaymentIntent {
  id: string;
  reference: string;
  status: 'requires_payment' | 'cancelled' | 'succeeded';
}

export interface CheckoutResult {
  order: OrderView;
  paymentIntent: PaymentIntent;
  reservedVariantIds: string[];
}

export class CheckoutError extends Error {
  constructor(
    public readonly code: string,
    message: string,
    public readonly httpStatus: number = 409,
  ) {
    super(message);
    this.name = code;
  }
}
