use std::{io, string::FromUtf8Error};

use http::{header::InvalidHeaderValue, status::InvalidStatusCode, Uri};

#[derive(Debug, thiserror::Error)]
pub enum HttpError<E: std::error::Error> {
    #[error("Malformed URL")]
    MalformedUrl,
    #[error("Unsupported URL scheme: {0}")]
    UnsupportedScheme(String),
    #[error("Connection error: {0}")]
    ConnectionError(E),
    #[error("Unexpected end of connection")]
    EndOfConnection,
    #[error("Malformed response header")]
    MalformedHeader(FromUtf8Error),
    #[error("Malformed header: {0}")]
    InvalidHeaderValue(InvalidHeaderValue),
    #[error("Request error: {0}")]
    Request(http::Error),
    #[error("Response error: {0}")]
    Response(http::Error),
    #[error("Hostname resolution error: {0}")]
    Hostname(io::Error),
    #[error("Invalid status code: {0}")]
    InvalidStatusCode(InvalidStatusCode),
    #[error("Invalid status line")]
    InvalidStatusLine,
    #[error("Could not read response body")]
    BodyError,
    #[error("Request too large")]
    RequestTooLarge,
    #[error("Could not connect to {0}")]
    CouldNotConnect(Uri),
}
