//
//  SDLAPIClient+Network.swift
//  punchnet
//
//  Created by 安礼成 on 2026/3/24.
//
import Foundation

struct NetworkService {
    
    static func connectNetwork(accesToken: String) async throws -> NetworkContext {
        let params: [String: Any] = [
            "client_id": SystemConfig.getClientId(),
            "access_token": accesToken
        ]
        
        return try await SDLAPIClient.doPost(path: "/connect", params: params, as: NetworkContext.self)
    }
    
    static func loadNodeResources(accesToken: String, id: Int) async -> [NetworkContext.Resource] {
        let params: [String: Any] = [
            "client_id": SystemConfig.getClientId(),
            "access_token": accesToken,
            "id": id
        ]
        
        if let detail = try? await SDLAPIClient.doPost(path: "/get_node_resources", params: params, as: NetworkContext.NodeDetail.self) {
            return detail.resourceList
        }
        
        return []
    }
    
}
