import HealthKit
import XCTest
@testable import HealthProbe

final class HealthKitAPICallResultTests: XCTestCase {
    func testProtectedDataInaccessibleDetectionRecognizesHealthKitDatabaseLockError() {
        let result = HealthKitAPICallResult(
            queryType: "earliest_sample",
            status: .failed,
            elapsedSeconds: 0,
            resultValue: nil,
            errorCode: "\(HKError.Code.errorDatabaseInaccessible.rawValue)",
            errorDomain: HKError.errorDomain,
            errorDescription: "Protected health data is inaccessible because the device is locked.",
            failureKind: "HealthKit error",
            cancellationReason: nil
        )

        XCTAssertTrue(result.indicatesProtectedDataInaccessible)
    }

    func testProtectedDataInaccessibleDetectionIgnoresOtherHealthKitFailures() {
        let result = HealthKitAPICallResult(
            queryType: "earliest_sample",
            status: .failed,
            elapsedSeconds: 0,
            resultValue: nil,
            errorCode: "\(HKError.Code.errorAuthorizationDenied.rawValue)",
            errorDomain: HKError.errorDomain,
            errorDescription: "Authorization denied.",
            failureKind: "HealthKit error",
            cancellationReason: nil
        )

        XCTAssertFalse(result.indicatesProtectedDataInaccessible)
    }
}
