import Testing
@testable import Alas

struct ThemeStoreTests {
    @Test func defaultIsCoolSlate() throws {
        let store = try ThemeStore()
        #expect(store.current.id == "cool-slate")
    }

    @Test func switchChangesCurrent() throws {
        let store = try ThemeStore()
        try store.activate(id: "light")
        #expect(store.current.id == "light")
    }

    @Test func switchToUnknownThrows() throws {
        let store = try ThemeStore()
        #expect(throws: Error.self) {
            try store.activate(id: "nope")
        }
    }

    @Test func matchSystemOffRestoresUserPick() throws {
        let store = try ThemeStore()
        try store.activate(id: "light")
        store.setMatchSystem(true)
        store.setMatchSystem(false)
        #expect(store.current.id == "light")
    }

    @Test func failedActivationPreservesUserPick() throws {
        let store = try ThemeStore()
        try store.activate(id: "light")

        #expect(throws: Error.self) {
            try store.activate(id: "nope")
        }

        store.setMatchSystem(true)
        store.setMatchSystem(false)
        #expect(store.current.id == "light")
    }
}
