//
//  MockLocationProvider.swift
//  suixinkanTests
//

import CoreLocation
@testable import suixinkan

/// 测试用定位替身。
final class MockLocationProvider: LocationProviding, @unchecked Sendable {
    var snapshot = HomeLocationSnapshot(latitude: 39.9087, longitude: 116.3975, address: "北京市东城区")
    var coordinate = CLLocationCoordinate2D(latitude: 39.9087, longitude: 116.3975)
    var reverseGeocodeResult = "北京市东城区"
    var requestSnapshotError: Error?
    var requestCoordinateError: Error?
    var requestedSnapshotAccuracies: [CLLocationAccuracy] = []
    var requestedAccuracies: [CLLocationAccuracy] = []

    func requestSnapshot(desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest) async throws -> HomeLocationSnapshot {
        requestedSnapshotAccuracies.append(desiredAccuracy)
        if let requestSnapshotError { throw requestSnapshotError }
        return snapshot
    }

    func requestCoordinate(desiredAccuracy: CLLocationAccuracy) async throws -> CLLocationCoordinate2D {
        requestedAccuracies.append(desiredAccuracy)
        if let requestCoordinateError { throw requestCoordinateError }
        return coordinate
    }

    func reverseGeocode(latitude: Double, longitude: Double) async -> String {
        reverseGeocodeResult
    }
}
