//
//  AppServiceEnvironment.swift
//  suixinkan
//
//  Created by Codex on 2026/6/26.
//

import SwiftUI

private enum EnvironmentServiceDefaults {
    static func apiClient() -> APIClient {
        APIClient()
    }
}

private struct APIClientEnvironmentKey: EnvironmentKey {
    static var defaultValue: APIClient { EnvironmentServiceDefaults.apiClient() }
}

private struct UploadAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: UploadAPI { UploadAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct PushAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: PushAPI { PushAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct AccountSnapshotStoreEnvironmentKey: EnvironmentKey {
    static var defaultValue: AccountSnapshotStore { AccountSnapshotStore() }
}

private struct AuthSessionCoordinatorEnvironmentKey: EnvironmentKey {
    static var defaultValue: AuthSessionCoordinator { AuthSessionCoordinator() }
}

private struct AccountContextAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: AccountContextAPI { AccountContextAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct AssetsAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: AssetsAPI { AssetsAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct AuthAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: AuthAPI { AuthAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct AppConfigAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: AppConfigAPI { AppConfigAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct InviteAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: InviteAPI { InviteAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct LiveAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: LiveAPI { LiveAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct LocationReportAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: LocationReportAPI { LocationReportAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct MessageCenterAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: MessageCenterAPI { MessageCenterAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct OperatingAreaAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: OperatingAreaAPI { OperatingAreaAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct OrdersAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: OrdersAPI { OrdersAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct OSSUploadServiceEnvironmentKey: EnvironmentKey {
    static var defaultValue: OSSUploadService {
        OSSUploadService(configService: UploadAPI(client: EnvironmentServiceDefaults.apiClient()))
    }
}

private struct PaymentAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: PaymentAPI { PaymentAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct PilotCertificationAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: PilotCertificationAPI { PilotCertificationAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct ProfileAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: ProfileAPI { ProfileAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct ProjectAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: ProjectAPI { ProjectAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct PunchPointAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: PunchPointAPI { PunchPointAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct ScenicPermissionAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: ScenicPermissionAPI { ScenicPermissionAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct ScenicQueueAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: ScenicQueueAPI { ScenicQueueAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct ScenicSettlementAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: ScenicSettlementAPI { ScenicSettlementAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct ScheduleAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: ScheduleAPI { ScheduleAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct StatisticsAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: StatisticsAPI { StatisticsAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct TaskAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: TaskAPI { TaskAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct TravelAlbumAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: TravelAlbumAPI { TravelAlbumAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct WalletAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: WalletAPI { WalletAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

private struct CooperationOrderAPIEnvironmentKey: EnvironmentKey {
    static var defaultValue: CooperationOrderAPI { CooperationOrderAPI(client: EnvironmentServiceDefaults.apiClient()) }
}

extension EnvironmentValues {
    var apiClient: APIClient {
        get { self[APIClientEnvironmentKey.self] }
        set { self[APIClientEnvironmentKey.self] = newValue }
    }

    var uploadAPI: UploadAPI {
        get { self[UploadAPIEnvironmentKey.self] }
        set { self[UploadAPIEnvironmentKey.self] = newValue }
    }

    var pushAPI: PushAPI {
        get { self[PushAPIEnvironmentKey.self] }
        set { self[PushAPIEnvironmentKey.self] = newValue }
    }

    var accountSnapshotStore: AccountSnapshotStore {
        get { self[AccountSnapshotStoreEnvironmentKey.self] }
        set { self[AccountSnapshotStoreEnvironmentKey.self] = newValue }
    }

    var authSessionCoordinator: AuthSessionCoordinator {
        get { self[AuthSessionCoordinatorEnvironmentKey.self] }
        set { self[AuthSessionCoordinatorEnvironmentKey.self] = newValue }
    }

    var accountContextAPI: AccountContextAPI {
        get { self[AccountContextAPIEnvironmentKey.self] }
        set { self[AccountContextAPIEnvironmentKey.self] = newValue }
    }

    var assetsAPI: AssetsAPI {
        get { self[AssetsAPIEnvironmentKey.self] }
        set { self[AssetsAPIEnvironmentKey.self] = newValue }
    }

    var authAPI: AuthAPI {
        get { self[AuthAPIEnvironmentKey.self] }
        set { self[AuthAPIEnvironmentKey.self] = newValue }
    }

    var appConfigAPI: AppConfigAPI {
        get { self[AppConfigAPIEnvironmentKey.self] }
        set { self[AppConfigAPIEnvironmentKey.self] = newValue }
    }

    var inviteAPI: InviteAPI {
        get { self[InviteAPIEnvironmentKey.self] }
        set { self[InviteAPIEnvironmentKey.self] = newValue }
    }

    var liveAPI: LiveAPI {
        get { self[LiveAPIEnvironmentKey.self] }
        set { self[LiveAPIEnvironmentKey.self] = newValue }
    }

    var locationReportAPI: LocationReportAPI {
        get { self[LocationReportAPIEnvironmentKey.self] }
        set { self[LocationReportAPIEnvironmentKey.self] = newValue }
    }

    var messageCenterAPI: MessageCenterAPI {
        get { self[MessageCenterAPIEnvironmentKey.self] }
        set { self[MessageCenterAPIEnvironmentKey.self] = newValue }
    }

    var operatingAreaAPI: OperatingAreaAPI {
        get { self[OperatingAreaAPIEnvironmentKey.self] }
        set { self[OperatingAreaAPIEnvironmentKey.self] = newValue }
    }

    var ordersAPI: OrdersAPI {
        get { self[OrdersAPIEnvironmentKey.self] }
        set { self[OrdersAPIEnvironmentKey.self] = newValue }
    }

    var ossUploadService: OSSUploadService {
        get { self[OSSUploadServiceEnvironmentKey.self] }
        set { self[OSSUploadServiceEnvironmentKey.self] = newValue }
    }

    var paymentAPI: PaymentAPI {
        get { self[PaymentAPIEnvironmentKey.self] }
        set { self[PaymentAPIEnvironmentKey.self] = newValue }
    }

    var pilotCertificationAPI: PilotCertificationAPI {
        get { self[PilotCertificationAPIEnvironmentKey.self] }
        set { self[PilotCertificationAPIEnvironmentKey.self] = newValue }
    }

    var profileAPI: ProfileAPI {
        get { self[ProfileAPIEnvironmentKey.self] }
        set { self[ProfileAPIEnvironmentKey.self] = newValue }
    }

    var projectAPI: ProjectAPI {
        get { self[ProjectAPIEnvironmentKey.self] }
        set { self[ProjectAPIEnvironmentKey.self] = newValue }
    }

    var punchPointAPI: PunchPointAPI {
        get { self[PunchPointAPIEnvironmentKey.self] }
        set { self[PunchPointAPIEnvironmentKey.self] = newValue }
    }

    var scenicPermissionAPI: ScenicPermissionAPI {
        get { self[ScenicPermissionAPIEnvironmentKey.self] }
        set { self[ScenicPermissionAPIEnvironmentKey.self] = newValue }
    }

    var scenicQueueAPI: ScenicQueueAPI {
        get { self[ScenicQueueAPIEnvironmentKey.self] }
        set { self[ScenicQueueAPIEnvironmentKey.self] = newValue }
    }

    var scenicSettlementAPI: ScenicSettlementAPI {
        get { self[ScenicSettlementAPIEnvironmentKey.self] }
        set { self[ScenicSettlementAPIEnvironmentKey.self] = newValue }
    }

    var scheduleAPI: ScheduleAPI {
        get { self[ScheduleAPIEnvironmentKey.self] }
        set { self[ScheduleAPIEnvironmentKey.self] = newValue }
    }

    var statisticsAPI: StatisticsAPI {
        get { self[StatisticsAPIEnvironmentKey.self] }
        set { self[StatisticsAPIEnvironmentKey.self] = newValue }
    }

    var taskAPI: TaskAPI {
        get { self[TaskAPIEnvironmentKey.self] }
        set { self[TaskAPIEnvironmentKey.self] = newValue }
    }

    var travelAlbumAPI: TravelAlbumAPI {
        get { self[TravelAlbumAPIEnvironmentKey.self] }
        set { self[TravelAlbumAPIEnvironmentKey.self] = newValue }
    }

    var walletAPI: WalletAPI {
        get { self[WalletAPIEnvironmentKey.self] }
        set { self[WalletAPIEnvironmentKey.self] = newValue }
    }

    var cooperationOrderAPI: CooperationOrderAPI {
        get { self[CooperationOrderAPIEnvironmentKey.self] }
        set { self[CooperationOrderAPIEnvironmentKey.self] = newValue }
    }
}
