Files
suixinkan_ios_uikit/suixinkan_ios/App/AppServices.swift
2026-06-26 14:33:31 +08:00

124 lines
4.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppServices.swift
// suixinkan
//
// Created by Codex on 2026/6/26.
//
import Foundation
@MainActor
/// ViewModel ViewController API
final class AppServices {
static let shared = AppServices()
let appSession = AppSession()
let accountContext = AccountContext()
let permissionContext = PermissionContext()
let scenicSpotContext = ScenicSpotContext()
let appRouter = AppRouter()
let toastCenter = ToastCenter()
let globalLoading = GlobalLoadingCenter()
let scenicQueueRuntime = ScenicQueueRuntime()
let apiClient: APIClient
let authAPI: AuthAPI
let profileAPI: ProfileAPI
let uploadAPI: UploadAPI
let ossUploadService: OSSUploadService
let accountContextAPI: AccountContextAPI
let ordersAPI: OrdersAPI
let statisticsAPI: StatisticsAPI
let paymentAPI: PaymentAPI
let walletAPI: WalletAPI
let pushAPI: PushAPI
let scenicPermissionAPI: ScenicPermissionAPI
let scenicSettlementAPI: ScenicSettlementAPI
let messageCenterAPI: MessageCenterAPI
let scenicQueueAPI: ScenicQueueAPI
let liveAPI: LiveAPI
let operatingAreaAPI: OperatingAreaAPI
let pilotCertificationAPI: PilotCertificationAPI
let taskAPI: TaskAPI
let projectAPI: ProjectAPI
let scheduleAPI: ScheduleAPI
let inviteAPI: InviteAPI
let assetsAPI: AssetsAPI
let punchPointAPI: PunchPointAPI
let locationReportAPI: LocationReportAPI
let authSessionCoordinator: AuthSessionCoordinator
let sessionBootstrapper: SessionBootstrapper
private let tokenStore: SessionTokenStore
private let snapshotStore: AccountSnapshotStore
/// ID
var currentScenicId: Int? {
accountContext.currentScenic?.id
}
/// staffId
var staffId: Int? {
Int(accountContext.profile?.userId ?? "")
}
/// ID
var userId: String? {
accountContext.profile?.userId
}
private init() {
let client = APIClient()
let tokenStore = SessionTokenStore()
let snapshotStore = AccountSnapshotStore()
self.tokenStore = tokenStore
self.snapshotStore = snapshotStore
apiClient = client
authAPI = AuthAPI(client: client)
profileAPI = ProfileAPI(client: client)
uploadAPI = UploadAPI(client: client)
ossUploadService = OSSUploadService(configService: uploadAPI)
accountContextAPI = AccountContextAPI(client: client)
ordersAPI = OrdersAPI(client: client)
statisticsAPI = StatisticsAPI(client: client)
paymentAPI = PaymentAPI(client: client)
walletAPI = WalletAPI(client: client)
pushAPI = PushAPI(client: client)
scenicPermissionAPI = ScenicPermissionAPI(client: client)
scenicSettlementAPI = ScenicSettlementAPI(client: client)
messageCenterAPI = MessageCenterAPI(client: client)
scenicQueueAPI = ScenicQueueAPI(client: client)
liveAPI = LiveAPI(client: client)
operatingAreaAPI = OperatingAreaAPI(client: client)
pilotCertificationAPI = PilotCertificationAPI(client: client)
taskAPI = TaskAPI(client: client)
projectAPI = ProjectAPI(client: client)
scheduleAPI = ScheduleAPI(client: client)
inviteAPI = InviteAPI(client: client)
assetsAPI = AssetsAPI(client: client)
punchPointAPI = PunchPointAPI(client: client)
locationReportAPI = LocationReportAPI(client: client)
authSessionCoordinator = AuthSessionCoordinator(
tokenStore: tokenStore,
snapshotStore: snapshotStore,
preferencesStore: AppPreferencesStore()
)
sessionBootstrapper = SessionBootstrapper(
tokenStore: tokenStore,
snapshotStore: snapshotStore
)
apiClient.bindAuthTokenProvider { [unowned self] in
appSession.token
}
}
/// UIKit
func configurePushNotifications() {
PushNotificationManager.shared.configure(
api: pushAPI,
session: appSession,
router: appRouter
)
}
}