use crate::container::environment::{RuntimeEnvironment, detect_runtime_environment};
use docker_compose_types;
use std::path::{Path, PathBuf};

/// Docker 服务状态
#[derive(Debug, Clone, PartialEq)]
pub enum ServiceStatus {
    Running,
    Stopped,
    Created,
    Restarting,
    Unknown,
}

impl ServiceStatus {
    /// 获取状态的中文显示名称
    pub fn display_name(&self) -> &'static str {
        match self {
            ServiceStatus::Running => "运行中",
            ServiceStatus::Stopped => "已停止",
            ServiceStatus::Created => "已创建",
            ServiceStatus::Restarting => "重启中",
            ServiceStatus::Unknown => "未知",
        }
    }
}

/// Docker 服务信息
#[derive(Debug, Clone)]
pub struct ServiceInfo {
    pub name: String,
    pub status: ServiceStatus,
    pub image: String,
    pub ports: Vec<String>,
}

/// 服务配置（从docker-compose.yml解析）
#[derive(Debug, Clone)]
pub struct ServiceConfig {
    pub restart: Option<String>,
}

/// Docker 服务管理器
#[derive(Debug, Clone)]
pub struct DockerManager {
    pub(crate) compose_file: PathBuf,
    pub(crate) env_file: PathBuf,
    pub(crate) compose_config: Option<docker_compose_types::Compose>,
    pub(crate) project_name: Option<String>,
    /// 运行时环境信息（新增）
    pub(crate) runtime_env: RuntimeEnvironment,
}

impl DockerManager {
    /// 获取运行时环境信息
    pub fn get_runtime_environment(&self) -> &RuntimeEnvironment {
        &self.runtime_env
    }

    /// 获取工作目录（compose 文件所在目录）
    pub fn get_working_directory(&self) -> Option<&Path> {
        self.compose_file.parent()
    }
}

// impl Default for DockerManager {
//     fn default() -> Self {
//         Self {
//             compose_file: get_compose_file_path(),
//             env_file: get_env_file_path(),
//             compose_config: None,
//         }
//     }
// }
