//! Request-side streaming types — the request counterpart to [`ResponseChunk`].
//!
//! In streaming mode (`stream_request_body`) the HTTP plugin delivers the
//! request body to PHP as a channel instead of buffering it. Two shapes:
//!
//! * [`RequestBody::Raw`] — opaque body bytes (`folk_read` / `folk_read_all`).
//! * [`RequestBody::Parts`] — a parsed `multipart/form-data` stream
//!   (`folk_next_part` + `folk_part_read`), produced by a `multer` task in the
//!   plugin so PHP never sees boundary bytes.
//!
//! [`ResponseChunk`]: crate::response::ResponseChunk

use bytes::Bytes;
use tokio::sync::mpsc;

/// One element of a streamed `multipart/form-data` request.
///
/// The plugin emits, per field: one [`RequestPart::Start`], zero or more
/// [`RequestPart::Data`] chunks, then one [`RequestPart::End`]. The channel
/// closing signals "no more parts".
#[derive(Debug, Clone)]
pub enum RequestPart {
    /// A new part begins. `name` is the form field name; `filename` is set for
    /// file parts (`None` for plain fields); `content_type` is the part's
    /// declared `Content-Type`, if any.
    Start {
        name: Option<String>,
        filename: Option<String>,
        content_type: Option<String>,
    },
    /// A chunk of the current part's body.
    Data(Bytes),
    /// The current part is complete.
    End,
}

/// What feeds a worker's request body in streaming mode.
///
/// Exactly one variant is created per streamed request, chosen by the HTTP
/// plugin from the request `Content-Type`.
pub enum RequestBody {
    /// Opaque body bytes — consumed by `folk_read` / `folk_read_all`.
    Raw(mpsc::Receiver<Bytes>),
    /// A parsed multipart stream — consumed by `folk_next_part` /
    /// `folk_part_read` / `folk_part_read_all`.
    Parts(mpsc::Receiver<RequestPart>),
}
