//
//  AppRegistering.swift
//  File
//
//  Created by Thomas Rademaker on 7/19/21.
//

import Foundation
import Networking

protocol AppRegistering {
    var router: NetworkRouter<AuthAPI> { get }
    
    func registerApp(clientName: String, redirectURI: String, scopes: [AccessScope], website: String) async throws -> ClientApplication
}

@available(iOS 15.0, *)
public class AppRegister: AppRegistering {
    var router: NetworkRouter<AuthAPI>
    
    public init(router: NetworkRouter<AuthAPI>, baseURLPath: String) {
        self.router = router
        AuthAPI.baseURLPath = baseURLPath
    }
    
    func registerApp(clientName: String, redirectURI: String, scopes: [AccessScope], website: String) async throws -> ClientApplication {
        try await router.execute(.registerClient(clientName: clientName, redirectURI: redirectURI, scopes: scopes, website: website))
    }
}
