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

use bollard::Docker;

use crate::{error::TestError, host_container::HostContainer};

/// Enum to represent the mode of the host.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
    Standalone,
    Containerized,
}

/// Struct to manage the host.
#[derive(Debug)]
pub struct Host {
    container: Option<HostContainer>,
}

impl Host {
    /// Get the current host.
    pub(crate) async fn current(docker: &Docker) -> Result<Self, TestError> {
        Ok(Self {
            container: HostContainer::current(docker).await?,
        })
    }

    /// Get the host container.
    pub fn container(&self) -> Option<&HostContainer> {
        self.container.as_ref()
    }

    /// Get the mode of the host.
    pub fn mode(&self) -> Mode {
        if self.container.is_none() {
            Mode::Standalone
        } else {
            Mode::Containerized
        }
    }
}
