import XCTest
import MapKit
@testable import SportsTime

final class ProgressMapViewTests: XCTestCase {

    @MainActor
    func test_MapViewModel_TracksUserInteraction() {
        // Given: A map view model
        let viewModel = MapInteractionViewModel()

        // When: User interacts with map (zoom/pan)
        viewModel.userDidInteract()

        // Then: Interaction is tracked
        XCTAssertTrue(viewModel.hasUserInteracted, "Should track user interaction")
        XCTAssertTrue(viewModel.shouldShowResetButton, "Should show reset button after interaction")
    }

    @MainActor
    func test_MapViewModel_ResetClearsInteraction() {
        // Given: A map with user interaction
        let viewModel = MapInteractionViewModel()
        viewModel.userDidInteract()

        // When: User resets the view
        viewModel.resetToDefault()

        // Then: Interaction flag is cleared
        XCTAssertFalse(viewModel.hasUserInteracted, "Should clear interaction flag after reset")
        XCTAssertFalse(viewModel.shouldShowResetButton, "Should hide reset button after reset")
    }

    @MainActor
    func test_MapViewModel_ZoomToStadium_SetsCorrectRegion() {
        // Given: A map view model
        let viewModel = MapInteractionViewModel()

        // When: Zooming to a stadium location
        let stadiumCoord = CLLocationCoordinate2D(latitude: 40.8296, longitude: -73.9262) // Yankee Stadium
        viewModel.zoomToStadium(at: stadiumCoord)

        // Then: Region is set to city-level zoom
        XCTAssertEqual(viewModel.region.center.latitude, stadiumCoord.latitude, accuracy: 0.001)
        XCTAssertEqual(viewModel.region.center.longitude, stadiumCoord.longitude, accuracy: 0.001)
        XCTAssertEqual(viewModel.region.span.latitudeDelta, 0.01, accuracy: 0.005, "Should use city-level zoom span")
    }
}
