export interface Market {
  d: string
  pubkey: string
  relays: string[]
  selected: boolean
  opts: {
    name: string
    description?: string
    logo?: string
    banner?: string
    merchants: string[]
    ui?: Record<string, any>
  }
}

export interface Stall {
  id: string
  pubkey: string
  name: string
  description?: string
  logo?: string
  categories?: string[]
  shipping?: ShippingZone[]
  shipping_zones?: ShippingZone[]  // LNbits format
  currency: string
  nostrEventId?: string
}

export interface Product {
  id: string
  stall_id: string
  stallName: string
  name: string
  description?: string
  price: number
  currency: string
  quantity: number
  images?: string[]
  categories?: string[]
  createdAt: number
  updatedAt: number
  nostrEventId?: string
}

export interface Order {
  id: string
  cartId: string
  stallId: string
  buyerPubkey: string
  sellerPubkey: string
  status: OrderStatus
  items: OrderItem[]
  contactInfo: ContactInfo
  shippingZone: ShippingZone
  paymentRequest?: string
  paymentMethod: PaymentMethod
  subtotal: number
  shippingCost: number
  total: number
  currency: string
  createdAt: number
  updatedAt: number
  nostrEventId?: string
  nostrEventSig?: string
  sentViaNostr?: boolean
  nostrError?: string
  originalOrderId?: string
  lightningInvoice?: any
  paymentHash?: string
  paidAt?: number
  paymentStatus?: 'pending' | 'paid' | 'expired'
  paid?: boolean  // Direct boolean field matching nostrmarket reference
  shipped?: boolean  // Shipping status from merchant updates
  qrCodeDataUrl?: string
  qrCodeLoading?: boolean
  qrCodeError?: string | null
  showQRCode?: boolean
}

export interface OrderItem {
  productId: string
  productName: string
  quantity: number
  price: number
  currency: string
}

export interface ContactInfo {
  address?: string
  email?: string
  message?: string
  npub?: string
}

export interface ShippingZone {
  id: string
  name: string
  cost: number
  currency: string
  countries?: string[]  // Countries/regions this zone covers
  description?: string
  estimatedDays?: string
  requiresPhysicalShipping?: boolean
}

export type OrderStatus = 'pending' | 'paid' | 'shipped' | 'delivered' | 'cancelled' | 'processing'

export type PaymentMethod = 'lightning' | 'btc_onchain'

export interface CartItem {
  product: Product
  quantity: number
  stallId: string
}

export interface StallCart {
  id: string
  merchant: string
  products: CartItem[]
  subtotal: number
  shippingZone?: ShippingZone
  currency: string
}

export interface FilterData {
  categories: string[]
  merchants: string[]
  stalls: string[]
  currency: string | null
  priceFrom: number | null
  priceTo: number | null
  inStock: boolean | null
  paymentMethods: PaymentMethod[]
}

export interface SortOptions {
  field: string
  order: 'asc' | 'desc'
}

export interface PaymentRequest {
  paymentRequest: string
  amount: number
  currency: string
  expiresAt: number
  description: string
}

export interface PaymentStatus {
  paid: boolean
  amountPaid: number
  paidAt?: number
  transactionId?: string
}