//
//  UploadAPI.swift
//  suixinkan
//

import Foundation

/// OSS 配置服务协议，抽象 STS token 获取能力，便于上传服务测试替换。
@MainActor
protocol OSSConfigServing {
    /// 获取指定 bucket 的阿里云 OSS 临时上传配置。
    func aliyunOSSBucket(bucket: String) async throws -> AliyunOSSResponse
}

@MainActor
/// 上传 API，封装文件上传前需要的服务端配置接口。
final class UploadAPI {
    private let client: APIClient

    init(client: APIClient) {
        self.client = client
    }

    /// 获取指定 bucket 的阿里云 OSS 临时上传配置。
    func aliyunOSSBucket(bucket: String = "vipsky") async throws -> AliyunOSSResponse {
        try await client.send(
            APIRequest(
                method: .get,
                path: "/api/app/config/get-sts-token",
                queryItems: [URLQueryItem(name: "bucket", value: bucket)]
            )
        )
    }
}

extension UploadAPI: OSSConfigServing {}
