1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{client::Client, login_state::LoginState};
use async_trait::async_trait;
use basws_shared::{
    protocol::{InstallationConfig, ServerError},
    Version,
};
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;
use url::Url;

#[async_trait]
pub trait ClientLogic: Send + Sync {
    type Request: Serialize + DeserializeOwned + Sync + Send + Clone + Debug;
    type Response: Serialize + DeserializeOwned + Sync + Send + Clone + Debug;

    fn server_url(&self) -> Url;
    fn protocol_version(&self) -> Version;

    async fn state_changed(&self, state: &LoginState, client: Client<Self>) -> anyhow::Result<()>;
    async fn stored_installation_config(&self) -> Option<InstallationConfig>;
    async fn store_installation_config(&self, config: InstallationConfig) -> anyhow::Result<()>;

    async fn response_received(
        &self,
        response: Self::Response,
        original_request_id: Option<u64>,
        client: Client<Self>,
    ) -> anyhow::Result<()>;

    async fn handle_server_error(
        &self,
        error: ServerError,
        client: Client<Self>,
    ) -> anyhow::Result<()>;
}