use warp::{http::Method, hyper::body::Bytes, path::FullPath, Filter};

pub type QueryParameters = Option<String>;
pub type Request = (FullPath, QueryParameters, Method, Bytes);

pub fn query_params_filter(
) -> impl Filter<Extract = (QueryParameters,), Error = std::convert::Infallible> + Clone {
    warp::query::raw()
        .map(Some)
        .or_else(|_| async { Ok::<(QueryParameters,), std::convert::Infallible>((None,)) })
}

pub fn extract_request_data_filter(
) -> impl Filter<Extract = Request, Error = warp::Rejection> + Clone {
    warp::path::full()
        .and(query_params_filter())
        .and(warp::method())
        .and(warp::body::bytes())
}
