diff --git a/SportsTime/Features/Trip/ViewModels/TripCreationViewModel.swift b/SportsTime/Features/Trip/ViewModels/TripCreationViewModel.swift index e320ee9..4685c25 100644 --- a/SportsTime/Features/Trip/ViewModels/TripCreationViewModel.swift +++ b/SportsTime/Features/Trip/ViewModels/TripCreationViewModel.swift @@ -280,16 +280,24 @@ final class TripCreationViewModel { func resolveLocations() async { do { - if !startLocationText.isEmpty { + // Only resolve if we don't already have a location with coordinates + // (LocationSearchSheet already provides full LocationInput with coordinates) + if !startLocationText.isEmpty && startLocation?.coordinate == nil { + print("🔍 resolveLocations: Resolving startLocation from text '\(startLocationText)'") startLocation = try await locationService.resolveLocation( LocationInput(name: startLocationText, address: startLocationText) ) + } else if startLocation?.coordinate != nil { + print("🔍 resolveLocations: startLocation already has coordinates, skipping resolve") } - if !endLocationText.isEmpty { + if !endLocationText.isEmpty && endLocation?.coordinate == nil { + print("🔍 resolveLocations: Resolving endLocation from text '\(endLocationText)'") endLocation = try await locationService.resolveLocation( LocationInput(name: endLocationText, address: endLocationText) ) + } else if endLocation?.coordinate != nil { + print("🔍 resolveLocations: endLocation already has coordinates, skipping resolve") } } catch { viewState = .error("Failed to resolve locations: \(error.localizedDescription)") @@ -337,10 +345,21 @@ final class TripCreationViewModel { case .locations: // Resolve provided locations + print("🔍 ViewModel.planTrip: .locations mode") + print(" - startLocationText: '\(startLocationText)'") + print(" - endLocationText: '\(endLocationText)'") + print(" - startLocation BEFORE resolve: \(startLocation?.name ?? "nil")") + print(" - endLocation BEFORE resolve: \(endLocation?.name ?? "nil")") + await resolveLocations() resolvedStartLocation = startLocation resolvedEndLocation = endLocation + print(" - startLocation AFTER resolve: \(startLocation?.name ?? "nil")") + print(" - endLocation AFTER resolve: \(endLocation?.name ?? "nil")") + print(" - resolvedStartLocation: \(resolvedStartLocation?.name ?? "nil")") + print(" - resolvedEndLocation: \(resolvedEndLocation?.name ?? "nil")") + guard resolvedStartLocation != nil, resolvedEndLocation != nil else { viewState = .error("Could not resolve start or end location") return diff --git a/SportsTime/Planning/Engine/ScenarioPlanner.swift b/SportsTime/Planning/Engine/ScenarioPlanner.swift index 6c0fcc0..d80bdfd 100644 --- a/SportsTime/Planning/Engine/ScenarioPlanner.swift +++ b/SportsTime/Planning/Engine/ScenarioPlanner.swift @@ -22,22 +22,32 @@ enum ScenarioPlannerFactory { /// Creates the appropriate planner based on the request inputs static func planner(for request: PlanningRequest) -> ScenarioPlanner { + print("🔍 ScenarioPlannerFactory: Selecting planner...") + print(" - followTeamId: \(request.preferences.followTeamId?.uuidString ?? "nil")") + print(" - selectedGames.count: \(request.selectedGames.count)") + print(" - startLocation: \(request.startLocation?.name ?? "nil")") + print(" - endLocation: \(request.endLocation?.name ?? "nil")") + // Scenario D: User wants to follow a specific team if request.preferences.followTeamId != nil { + print("🔍 ScenarioPlannerFactory: → ScenarioDPlanner (follow team)") return ScenarioDPlanner() } // Scenario B: User selected specific games if !request.selectedGames.isEmpty { + print("🔍 ScenarioPlannerFactory: → ScenarioBPlanner (selected games)") return ScenarioBPlanner() } // Scenario C: User specified start and end locations if request.startLocation != nil && request.endLocation != nil { + print("🔍 ScenarioPlannerFactory: → ScenarioCPlanner (start/end locations)") return ScenarioCPlanner() } // Scenario A: Date range only (default) + print("🔍 ScenarioPlannerFactory: → ScenarioAPlanner (default/date range)") return ScenarioAPlanner() }