import Foundation
import HealthKit

// Interface updated 2026-05-18 — see AGENTS.md
protocol HealthArchiveStore {
    func upsertSamples(_ samples: [HKSample], observedAt: Date) async throws -> HealthArchiveWriteSummary
    func markVerification(sampleType: HKSampleType, verifiedAt: Date) async throws
    func recordDisappearance(sampleUUIDHash: String, sampleTypeIdentifier: String, observedMissingAt: Date) async throws
    func records(for request: HealthArchiveRecordRequest) async throws -> [ArchivedHealthRecord]
    func exportReport(_ request: HealthArchiveReportRequest) async throws -> URL
}

struct HealthArchiveWriteSummary: Equatable, Sendable {
    let insertedCount: Int
    let updatedCount: Int
    let unchangedCount: Int
}

struct HealthArchiveRecordRequest: Equatable, Sendable {
    let sampleTypeIdentifier: String?
    let fingerprints: Set<String>
    let limit: Int?
}

struct HealthArchiveReportRequest: Equatable, Sendable {
    let reportID: UUID
    let title: String
    let includedFingerprints: Set<String>
}

struct ArchivedHealthRecord: Identifiable, Equatable, Sendable, Encodable {
    let id: String
    let sampleTypeIdentifier: String
    let strictFingerprint: String
    let semanticFingerprint: String?
    let healthKitUUIDHash: String?
    let startDate: Date
    let endDate: Date
    let firstSeenAt: Date
    let lastSeenAt: Date?
    let lastVerifiedAt: Date?
    let disappearedAt: Date?
}
