//
//  SessionSnapshot.swift
//  Tun
//
//  Created by Codex on 2026/5/21.
//
import Foundation

final class SessionSnapshot: Snapshot {
    private let sessions: [Data: [Session.AddressType: Session]]

    init(sessions: [Data: [Session.AddressType: Session]]) {
        self.sessions = sessions
    }

    func getSession(toAddress: Data) -> Session? {
        guard let peerSessions = self.sessions[toAddress] else {
            return nil
        }

        return peerSessions.values.max(by: { $0.lastTimestamp < $1.lastTimestamp })
    }

    static func empty() -> SessionSnapshot {
        return SessionSnapshot(sessions: [:])
    }
}
