import Foundation

/// Original-file download URL builder. CRITICAL: this endpoint authenticates via the `?token=` QUERY
/// parameter, NOT an Authorization header (iframe/download compatibility). The token must live only in
/// the query. Callers must redact the token when logging the URL.
public enum DSDownload {
    public static func fileURL(
        base: DSBaseURL,
        documentID id: Int,
        accessToken: String,
        download: Bool = true
    ) -> URL? {
        let endpoint = base.url.appendingPathComponent("documents/\(id)/file")
        var comps = URLComponents(url: endpoint, resolvingAgainstBaseURL: false)
        comps?.queryItems = [
            URLQueryItem(name: "token", value: accessToken),
            URLQueryItem(name: "download", value: download ? "true" : "false"),
        ]
        return comps?.url
    }
}
