//! Payment method microservice flows and lightweight client context.

/// Create payment method flow.
#[cfg(feature = "v1")]
pub mod create;
/// Delete payment method flow.
pub mod delete;
/// List customer payment methods flow.
#[cfg(feature = "v1")]
pub mod list;
#[cfg(feature = "v1")]
/// Retrieve payment method flow.
pub mod retrieve;
/// Payment method session create flow.
pub mod session;
/// Update payment method flow.
#[cfg(feature = "v1")]
pub mod update;

use common_utils::request::Headers;
#[cfg(feature = "v1")]
pub use create::{CreatePaymentMethod, CreatePaymentMethodV1Request};
pub use delete::{DeletePaymentMethod, DeletePaymentMethodV1Request};
use hyperswitch_interfaces::micro_service::MicroserviceClient;
#[cfg(feature = "v1")]
pub use retrieve::{RetrievePaymentMethod, RetrievePaymentMethodV1Request};
use router_env::RequestIdentifier;
pub use session::{
    CreatePaymentMethodSession, CreatePaymentMethodSessionResponse,
    CreatePaymentMethodSessionV1Request,
};
#[cfg(feature = "v1")]
pub use update::{
    BankDebitDetailUpdate, CardDetailUpdate, PaymentMethodUpdateData, UpdatePaymentMethod,
    UpdatePaymentMethodV1Payload, UpdatePaymentMethodV1Request,
};

use crate::configs::ModularPaymentMethodServiceUrl;

#[derive(Debug)]
/// Lightweight client context for payment method microservice calls.
pub struct PaymentMethodClient<'a> {
    /// Base URL for the payment method service.
    pub base_url: &'a ModularPaymentMethodServiceUrl,
    /// Parent headers to propagate to the microservice.
    pub parent_headers: &'a Headers,
    /// Trace configuration for request correlation.
    pub trace: RequestIdentifier,
}

impl<'a> PaymentMethodClient<'a> {
    /// Create a new client with base URL, parent headers, and trace configuration.
    pub fn new(
        base_url: &'a ModularPaymentMethodServiceUrl,
        parent_headers: &'a Headers,
        trace_header_name: &'a str,
    ) -> Self {
        // For internal service calls, use the same request ID generated by the application.
        let trace = RequestIdentifier::new(trace_header_name)
            .use_incoming_id(router_env::IdReuse::UseIncoming);
        Self {
            base_url,
            parent_headers,
            trace,
        }
    }
}

impl MicroserviceClient for PaymentMethodClient<'_> {
    fn base_url(&self) -> &url::Url {
        self.base_url.as_ref()
    }

    fn parent_headers(&self) -> &Headers {
        self.parent_headers
    }

    fn trace(&self) -> &RequestIdentifier {
        &self.trace
    }
}
