//
//  UITestAuthenticatedSession.swift
//  suixinkanUITests
//
//  Created by Codex on 2026/6/26.
//

import XCTest

/// 已登录会话启动器，供需要主界面的 UI Test 复用。
enum UITestAuthenticatedSession {
    /// 启动 App 并完成登录，返回配置好的应用包装器。
    static func launchLoggedIn(
        resetState: Bool = false,
        openMenuTitle: String? = nil,
        openProfileRoute: String? = nil,
        file: StaticString = #filePath,
        line: UInt = #line
    ) throws -> SuixinkanApp {
        let credentials = try UITestLaunchConfiguration.requireCredentials(file: file, line: line)
        let app = SuixinkanApp(
            resetState: resetState,
            openMenuTitle: openMenuTitle,
            openProfileRoute: openProfileRoute
        ).launch()
        app.waitForInitialScreen()
        LoginFlow.loginIfNeeded(app: app, credentials: credentials, file: file, line: line)
        app.waitForGlobalLoadingToDisappear()
        return app
    }
}
