use ftypes::{Error, ReceivedMessage, SignalServers, Store};
use phonenumber::PhoneNumber;
use url::Url;

use crate::ManagerHandle;

#[derive(Clone, Debug)]
pub enum SetupDecision {
    Register(RegisterSetup),
    Link(LinkSetup),
}

#[derive(Clone, Debug)]
pub struct RegisterSetup {
    pub servers: SignalServers,
    pub phone_number: PhoneNumber,
    pub captcha: String,
}

#[derive(Clone, Debug)]
pub struct LinkSetup {
    pub servers: SignalServers,
    pub device_name: String,
}

pub trait SignalClient<S: Store> {
    fn request_setup_decision(&self) -> impl Future<Output = SetupDecision>;
    fn request_qrcode_scan(&self, url: Url) -> impl Future<Output = ()>;
    fn request_confirmation_code(&self) -> impl Future<Output = String>;
    fn setup_complete(&self, handle: ManagerHandle<S>) -> impl Future<Output = ()>;

    fn queue_empty(&self) -> impl Future<Output = ()> {
        std::future::ready(())
    }

    fn error(&self, error: Error) -> impl Future<Output = ()> {
        log::error!("{}", error);
        std::future::ready(())
    }

    fn on_message(&self, message: ReceivedMessage) -> impl Future<Output = ()>;
}
