Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

use classy::hl::{BodyState, HttpClientResponse, RequestBodyState, ResponseBodyState};

#[cfg(feature = "enable_stop_iteration")]
use classy::hl::{HeadersBodyState, RequestHeadersBodyState, ResponseHeadersBodyState};

/// Binding for the top-level `payload` variable.
pub trait PayloadBinding {
    /// Returns the payload in binary format.
    fn as_bytes(&self) -> Vec<u8>;
}

impl PayloadBinding for &[u8] {
    fn as_bytes(&self) -> Vec<u8> {
        self.to_vec()
    }
}

impl PayloadBinding for String {
    fn as_bytes(&self) -> Vec<u8> {
        self.as_bytes().to_vec()
    }
}

impl PayloadBinding for RequestBodyState {
    fn as_bytes(&self) -> Vec<u8> {
        self.handler().body()
    }
}

#[cfg(feature = "enable_stop_iteration")]
impl PayloadBinding for RequestHeadersBodyState {
    fn as_bytes(&self) -> Vec<u8> {
        self.handler().body()
    }
}

impl PayloadBinding for ResponseBodyState {
    fn as_bytes(&self) -> Vec<u8> {
        self.handler().body()
    }
}

#[cfg(feature = "enable_stop_iteration")]
impl PayloadBinding for ResponseHeadersBodyState {
    fn as_bytes(&self) -> Vec<u8> {
        self.handler().body()
    }
}

impl PayloadBinding for HttpClientResponse {
    fn as_bytes(&self) -> Vec<u8> {
        self.body().to_vec()
    }
}