use super::error::Error;
use async_trait::async_trait;
use futures::future::BoxFuture;
use reqwest::Client;
use std::fmt::Debug;

#[async_trait]
pub trait VideoThumbnailExtractorExt: Debug + Send + Sync {
    fn matches_url(&self, video_url: &str) -> bool;
    async fn get_thumbnail_url(&self, video_url: &str, client: &Client) -> Result<String, Error>;
}

#[async_trait]
pub trait ClientRequestorExt: Send + Sync {
    async fn get_client(&self) -> Client;
}

#[async_trait]
impl ClientRequestorExt for Box<dyn Fn() -> Client + Send + Sync> {
    async fn get_client(&self) -> Client {
        self()
    }
}

#[async_trait]
impl<'a> ClientRequestorExt for Box<dyn Fn() -> BoxFuture<'a, Client> + Send + Sync> {
    async fn get_client(&self) -> Client {
        self().await
    }
}
