import Foundation
import AlignerCore

final class DebugWindowCloseService: WindowCloseServiceProtocol {
    private(set) var closedWindowIDs: [UInt32] = []
    private(set) var closedAppProcessIdentifiers: [Int32] = []

    func close(window: AlignerWindow) throws -> WindowCloseResult {
        closedWindowIDs.append(window.id)
        if ProcessInfo.processInfo.environment["ALIGNER_DEBUG_WINDOW_CLOSE_RESULT"] == "windowNotFound" {
            return .windowNotFound
        }
        return .requested
    }

    func close(app: AlignerApp) throws -> WindowCloseResult {
        if let processIdentifier = app.processIdentifier {
            closedAppProcessIdentifiers.append(processIdentifier)
        }
        if ProcessInfo.processInfo.environment["ALIGNER_DEBUG_WINDOW_CLOSE_RESULT"] == "windowNotFound" {
            return .windowNotFound
        }
        return .requested
    }
}
