use crate::connection::HttpConnection;

pub trait HttpBody: Sized {
    fn from_response(content_length: Option<usize>) -> Option<Self>;
    fn write<C: HttpConnection>(&self, connection: &mut C) -> Result<(), C::Error>;
    fn content_length(&self) -> Option<usize>;
}

#[derive(Debug)]
pub struct Bytes {
    pub(crate) content_length: Option<usize>,
}

impl HttpBody for () {
    fn from_response(content_length: Option<usize>) -> Option<Self> {
        let _ = content_length;
        Some(())
    }

    fn content_length(&self) -> Option<usize> {
        Some(0)
    }

    fn write<C: HttpConnection>(&self, connection: &mut C) -> Result<(), C::Error> {
        let _ = connection;
        Ok(())
    }
}

impl HttpBody for Bytes {
    fn from_response(content_length: Option<usize>) -> Option<Self> {
        Some(Self { content_length })
    }

    fn content_length(&self) -> Option<usize> {
        self.content_length
    }

    fn write<C: HttpConnection>(&self, connection: &mut C) -> Result<(), C::Error> {
        let _ = connection;
        todo!()
    }
}
