import XCTest
@testable import CommandNotch

final class WorkspaceStoreTests: XCTestCase {
    func testWorkspaceStoreRoundTripsSummaries() {
        let defaults = UserDefaults(suiteName: #function)!
        defaults.removePersistentDomain(forName: #function)
        defer { defaults.removePersistentDomain(forName: #function) }

        let store = UserDefaultsWorkspaceStore(defaults: defaults)
        let summaries = [
            WorkspaceSummary(
                id: UUID(uuidString: "11111111-1111-1111-1111-111111111111")!,
                name: "Main",
                hotkey: HotkeyBinding.cmdShiftDigit(4)
            ),
            WorkspaceSummary(id: UUID(uuidString: "22222222-2222-2222-2222-222222222222")!, name: "Docs")
        ]

        store.saveWorkspaceSummaries(summaries)

        XCTAssertEqual(store.loadWorkspaceSummaries(), summaries)
    }

    func testScreenAssignmentStoreRoundTripsAssignments() {
        let defaults = UserDefaults(suiteName: #function)!
        defaults.removePersistentDomain(forName: #function)
        defer { defaults.removePersistentDomain(forName: #function) }

        let store = UserDefaultsScreenAssignmentStore(defaults: defaults)
        let assignments: [ScreenID: WorkspaceID] = [
            "screen-a": UUID(uuidString: "11111111-1111-1111-1111-111111111111")!,
            "screen-b": UUID(uuidString: "22222222-2222-2222-2222-222222222222")!
        ]

        store.saveScreenAssignments(assignments)

        XCTAssertEqual(store.loadScreenAssignments(), assignments)
    }
}
