// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.

/// Generated endpoint tests
#[cfg(test)]
mod test {}

#[non_exhaustive]
#[derive(std::clone::Clone, std::cmp::PartialEq, std::fmt::Debug)]
/// Configuration parameters for resolving the correct endpoint
pub struct Params {
    /// The region to dispatch this request, eg. `us`.
    pub(crate) region: std::string::String,
    pub(crate) stage: std::option::Option<std::string::String>,
    /// Override the endpoint used to send this request
    pub(crate) endpoint: std::option::Option<std::string::String>,
}
impl Params {
    /// Create a builder for [`Params`]
    pub fn builder() -> crate::endpoint::ParamsBuilder {
        crate::endpoint::ParamsBuilder::default()
    }
    /// The region to dispatch this request, eg. `us`.
    pub fn region(&self) -> std::option::Option<&str> {
        Some(&self.region)
    }
    /// Gets the value for `stage`
    pub fn stage(&self) -> std::option::Option<&str> {
        self.stage.as_deref()
    }
    /// Override the endpoint used to send this request
    pub fn endpoint(&self) -> std::option::Option<&str> {
        self.endpoint.as_deref()
    }
}

/// The default endpoint resolver
#[derive(Default)]
pub struct DefaultResolver {}

impl DefaultResolver {
    /// Create a new endpoint resolver with default settings
    pub fn new() -> Self {
        Self {}
    }
}

impl aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params> for DefaultResolver {
    fn resolve_endpoint(&self, params: &Params) -> aws_smithy_http::endpoint::Result {
        let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
        crate::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector)
            .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))
    }
}

/// Builder for [`Params`]
#[derive(std::clone::Clone, std::cmp::PartialEq, std::default::Default, std::fmt::Debug)]
pub struct ParamsBuilder {
    region: std::option::Option<std::string::String>,
    stage: std::option::Option<std::string::String>,
    endpoint: std::option::Option<std::string::String>,
}
impl ParamsBuilder {
    /// Consume this builder, creating [`Params`].
    pub fn build(self) -> Result<crate::endpoint::Params, crate::endpoint::InvalidParams> {
        Ok(
            #[allow(clippy::unnecessary_lazy_evaluations)]
            crate::endpoint::Params {
                region: self
                    .region
                    .or_else(|| Some("us".to_string()))
                    .ok_or_else(|| crate::endpoint::InvalidParams::missing("region"))?,
                stage: self.stage,
                endpoint: self.endpoint,
            },
        )
    }
    /// Sets the value for region
    ///
    /// When unset, this parameter has a default value of `us`.
    /// The region to dispatch this request, eg. `us`.
    pub fn region(mut self, value: impl Into<std::string::String>) -> Self {
        self.region = Some(value.into());
        self
    }

    /// Sets the value for region
    ///
    /// When unset, this parameter has a default value of `us`.
    /// The region to dispatch this request, eg. `us`.
    pub fn set_region(mut self, param: Option<std::string::String>) -> Self {
        self.region = param;
        self
    }
    /// Sets the value for stage
    pub fn stage(mut self, value: impl Into<std::string::String>) -> Self {
        self.stage = Some(value.into());
        self
    }

    /// Sets the value for stage
    pub fn set_stage(mut self, param: Option<std::string::String>) -> Self {
        self.stage = param;
        self
    }
    /// Sets the value for endpoint
    ///
    /// Override the endpoint used to send this request
    pub fn endpoint(mut self, value: impl Into<std::string::String>) -> Self {
        self.endpoint = Some(value.into());
        self
    }

    /// Sets the value for endpoint
    ///
    /// Override the endpoint used to send this request
    pub fn set_endpoint(mut self, param: Option<std::string::String>) -> Self {
        self.endpoint = param;
        self
    }
}

/// An error that occurred during endpoint resolution
#[derive(Debug)]
pub struct InvalidParams {
    field: std::borrow::Cow<'static, str>,
}

impl InvalidParams {
    #[allow(dead_code)]
    fn missing(field: &'static str) -> Self {
        Self {
            field: field.into(),
        }
    }
}

impl std::fmt::Display for InvalidParams {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "a required field was missing: `{}`", self.field)
    }
}

impl std::error::Error for InvalidParams {}

/// Endpoints internals
mod internals;
