Services
All services are singletons accessed via .shared, using SupabaseManager.shared.client for database operations.
AuthService
File: Services/AuthService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
getCurrentUser() | — | User? | Get current authenticated user |
getSession() | — | Session? | Get current session |
signOut() | — | Void | Sign out |
signUp(email:password:fullName:birthday:) | String, String, String?, String? | Session | Create account |
signIn(email:password:) | String, String | Session | Email sign in |
signInWithGoogle() | — | Void | OAuth with Google |
signInWithApple() | — | Void | OAuth with Apple |
getProfile(userId:) | String | Profile? | Fetch profile |
updateProfile(userId:fullName:phone:) | String, String?, String? | Profile | Update profile |
observeAuthStateChanges() | — | AsyncStream<AuthChangeEvent> | Auth state stream |
MenuService
File: Services/MenuService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
getCategories() | — | [MenuCategory] | Active categories, sorted |
getMenuItems(category:) | String? | [MenuItem] | Available items, optional filter |
getFeaturedItems() | — | [MenuItem] | Featured items |
getItemDetails(id:) | String | MenuItemWithModifiers | Full item with modifiers |
searchItems(query:) | String | [MenuItem] | Search by name/description |
Uses MenuCache and ModifierCache for local caching.
OrderService
File: Services/OrderService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
createOrder(items:subtotal:tax:discount:tip:total:paymentMethod:squarePaymentId:squareOrderId:locationName:) | Multiple | Order | Create full order |
getUserOrders() | — | [OrderWithItems] | Current user’s orders |
getOrder(id:) | String | OrderWithItems | Single order with items |
syncToSquare(orderId:items:subtotal:tax:tip:total:orderNumber:idempotencyKey:) | Multiple | String | Sync to Square, returns Square order ID |
Errors: notAuthenticated, noLocationFound, invalidResponse, serverError, squareSyncFailed
LoyaltyService
File: Services/LoyaltyService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
getLoyaltyData() | — | LoyaltyResponse | Account + transactions + rewards |
getAvailableRewards(tier:) | LoyaltyTier | [Reward] | Rewards accessible at tier |
redeemReward(rewardId:) | String | RedeemRewardResponse | Redeem a reward |
Errors: notAuthenticated, noLoyaltyAccount, insufficientStars, tierRequirementNotMet
SquarePaymentService
File: Services/SquarePaymentService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
processPayment(sourceId:amount:currency:idempotencyKey:note:) | Multiple | PaymentResult | Process card payment |
processApplePayPayment(paymentData:amount:) | Data, Int | PaymentResult | Process Apple Pay |
createPayAtCounterPayment(amount:) | Int | PaymentResult | Counter payment stub |
isApplePayAvailable | — | Bool | Device Apple Pay support |
Payment Methods: payAtCounter, applePay, card
ApplePayService
File: Services/ApplePayService.swift
Handles Apple Pay via PassKit framework. Creates PKPaymentRequest with itemized summary, supported networks (Visa, Mastercard, Amex, Discover), and merchant ID merchant.com.staccato.coffee.
CartStorageService
File: Services/CartStorageService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
saveCart(_:) | [CartItem] | Void | Persist to UserDefaults |
loadCart() | — | [CartItem] | Load from UserDefaults |
clearCart() | — | Void | Clear saved cart |
Storage key: staccato-cart
OrderQueueService
File: Services/OrderQueueService.swift
| Method | Parameters | Returns | Description |
|---|---|---|---|
getActiveOrders() | — | [OrderWithItems] | Pending + in_progress + ready |
getOrders(status:) | OrderStatus | [Order] | Orders by status |
claimOrder(orderId:) | String | Void | Claim for current user |
markReady(orderId:) | String | Void | Mark as ready |
completeOrder(orderId:) | String | Void | Mark as completed |
unclaimOrder(orderId:) | String | Void | Release back to queue |
Errors: notAuthenticated, orderAlreadyClaimed, notAssignedToYou, invalidStatusTransition
AnalyticsService
File: Services/AnalyticsService.swift
| Method | Parameters | Returns |
|---|---|---|
getDailySales(days:) | Int | [DailySales] |
getSalesSummary(days:) | Int | SalesSummary |
getHourlyDistribution() | — | [HourlyDistribution] |
getTopItems(limit:) | Int | [TopItem] |
getPopularModifiers(limit:) | Int | [PopularModifier] |
getLoyaltyTierDistribution() | — | [LoyaltyTierStats] |
getStarTransactionsSummary(days:) | Int | StarTransactionsSummary |
getOrderStatusBreakdown() | — | [OrderStatusStats] |
getEmployeePerformance() | — | [EmployeePerformance] |
getNewCustomers(days:) | Int | Int |
getTotalCustomers() | — | Int |