//
//  ScenarioPlanner.swift
//  SportsTime
//
//  Protocol for scenario-based trip planning.
//

import Foundation

/// Protocol that all scenario planners must implement.
/// Each scenario (A, B, C) has its own isolated implementation.
protocol ScenarioPlanner {

    /// Plan itineraries for this scenario.
    /// - Parameter request: The planning request with all inputs
    /// - Returns: Success with ranked itineraries, or explicit failure
    func plan(request: PlanningRequest) -> ItineraryResult
}

/// Factory for creating the appropriate scenario planner
enum ScenarioPlannerFactory {

    /// Creates the appropriate planner based on the request inputs
    static func planner(for request: PlanningRequest) -> ScenarioPlanner {
        // Scenario B: User selected specific games
        if !request.selectedGames.isEmpty {
            return ScenarioBPlanner()
        }

        // Scenario C: User specified start and end locations
        if request.startLocation != nil && request.endLocation != nil {
            return ScenarioCPlanner()
        }

        // Scenario A: Date range only (default)
        return ScenarioAPlanner()
    }

    /// Classifies which scenario applies to this request
    static func classify(_ request: PlanningRequest) -> PlanningScenario {
        if !request.selectedGames.isEmpty {
            return .scenarioB
        }
        if request.startLocation != nil && request.endLocation != nil {
            return .scenarioC
        }
        return .scenarioA
    }
}
