use crate::{config, error::Error, Auth};
use soph_config::traits::ConfigurationTrait;
use soph_core::{
    error::ContainerError,
    support::Container,
    traits::{ErrorTrait, InstanceTrait},
    Result,
};

impl InstanceTrait for Auth {
    fn register(container: &Container) -> Result<Self, ContainerError>
    where
        Self: Sized,
    {
        let config = container
            .resolve::<soph_config::Config>()?
            .get::<config::Auth>("auth")
            .map_err(Error::wrap)?;

        Ok(Self::try_from_config(config).map_err(Error::wrap)?)
    }
}
