import Foundation

protocol SpaceActivationServiceProtocol: AnyObject {
    func activate(spaceID: UInt64) -> PrivateSpaceFocusOutcome
}

final class PrivateSpaceActivationService: SpaceActivationServiceProtocol {
    private let bridge: PrivateSpaceActivationBridge?

    init(bridge: PrivateSpaceActivationBridge? = .shared) {
        self.bridge = bridge
    }

    func activate(spaceID: UInt64) -> PrivateSpaceFocusOutcome {
        guard let outcome = bridge?.focus(spaceIDs: [spaceID]) else {
            return PrivateSpaceFocusOutcome(
                targetSpaceID: spaceID,
                displayIdentifier: nil,
                previousCurrentSpaceID: nil,
                didRequestFocus: false,
                error: "spaceActivationBridgeUnavailable"
            )
        }

        return outcome
    }
}

final class DebugSpaceActivationService: SpaceActivationServiceProtocol {
    func activate(spaceID: UInt64) -> PrivateSpaceFocusOutcome {
        PrivateSpaceFocusOutcome(
            targetSpaceID: spaceID,
            displayIdentifier: "debug",
            previousCurrentSpaceID: nil,
            didRequestFocus: true,
            error: nil
        )
    }
}
