use super::types::{CentralEvent, ScanFilter, WriteType};
use crate::error::BlewResult;
use crate::gatt::service::GattService;
use crate::l2cap::{L2capChannel, types::Psm};
use crate::types::{BleDevice, DeviceId};
use futures_core::Stream;
use std::future::Future;
use uuid::Uuid;
pub(crate) mod private {
pub trait Sealed {}
}
pub trait CentralBackend: private::Sealed + Send + Sync + 'static {
type EventStream: Stream<Item = CentralEvent> + Send + Unpin + 'static;
fn new() -> impl Future<Output = BlewResult<Self>> + Send
where
Self: Sized;
fn is_powered(&self) -> impl Future<Output = BlewResult<bool>> + Send;
fn start_scan(&self, filter: ScanFilter) -> impl Future<Output = BlewResult<()>> + Send;
fn stop_scan(&self) -> impl Future<Output = BlewResult<()>> + Send;
fn discovered_devices(&self) -> impl Future<Output = BlewResult<Vec<BleDevice>>> + Send;
fn connect(&self, device_id: &DeviceId) -> impl Future<Output = BlewResult<()>> + Send;
fn disconnect(&self, device_id: &DeviceId) -> impl Future<Output = BlewResult<()>> + Send;
fn discover_services(
&self,
device_id: &DeviceId,
) -> impl Future<Output = BlewResult<Vec<GattService>>> + Send;
fn read_characteristic(
&self,
device_id: &DeviceId,
char_uuid: Uuid,
) -> impl Future<Output = BlewResult<Vec<u8>>> + Send;
fn write_characteristic(
&self,
device_id: &DeviceId,
char_uuid: Uuid,
value: Vec<u8>,
write_type: WriteType,
) -> impl Future<Output = BlewResult<()>> + Send;
fn subscribe_characteristic(
&self,
device_id: &DeviceId,
char_uuid: Uuid,
) -> impl Future<Output = BlewResult<()>> + Send;
fn unsubscribe_characteristic(
&self,
device_id: &DeviceId,
char_uuid: Uuid,
) -> impl Future<Output = BlewResult<()>> + Send;
fn mtu(&self, device_id: &DeviceId) -> impl Future<Output = u16> + Send;
fn open_l2cap_channel(
&self,
device_id: &DeviceId,
psm: Psm,
) -> impl Future<Output = BlewResult<L2capChannel>> + Send;
fn events(&self) -> Self::EventStream;
}