import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

public actor Bot {
    public let client: ApiClient
    let gateway: GatewayClient

    public init(token: String, intents: Intents) async throws {
        client = ApiClient(token: token)
        let gatewayURL = try await client.getGatewayURL()
        gateway = GatewayClient(gatewayURL: gatewayURL, token: token, intents: intents)
    }

    public func connect() async throws {
        try await gateway.openConnection()
    }

    public var events: AsyncStream<GatewayPayload> {
        get async { await gateway.events }
    }
}
