//! Deployment service types

use std::path::PathBuf;
use std::str::FromStr;

/// Deployment configuration
#[derive(Debug, Clone)]
pub struct DeployConfig {
    pub host: String,
    pub user: String,
    pub port: u16,
    pub ssh_key: Option<PathBuf>,
    pub remote_dir: String,
    pub service_name: String,
    pub backup_dir: String,
    pub health_check_timeout: u64,
    pub health_check_retries: u32,
}

impl Default for DeployConfig {
    fn default() -> Self {
        Self {
            host: "robot.local".to_string(),
            user: "mecha10".to_string(),
            port: 22,
            ssh_key: None,
            remote_dir: "/opt/mecha10".to_string(),
            service_name: "mecha10-robot".to_string(),
            backup_dir: "/opt/mecha10/backups".to_string(),
            health_check_timeout: 30,
            health_check_retries: 3,
        }
    }
}

/// Deployment strategy
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeployStrategy {
    Direct,
    Canary,
    Rolling,
    BlueGreen,
}

impl FromStr for DeployStrategy {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "direct" => Ok(DeployStrategy::Direct),
            "canary" => Ok(DeployStrategy::Canary),
            "rolling" => Ok(DeployStrategy::Rolling),
            "blue-green" | "bluegreen" => Ok(DeployStrategy::BlueGreen),
            _ => Err(format!("Invalid deployment strategy: {}", s)),
        }
    }
}

impl DeployStrategy {
    pub fn as_str(&self) -> &str {
        match self {
            DeployStrategy::Direct => "direct",
            DeployStrategy::Canary => "canary",
            DeployStrategy::Rolling => "rolling",
            DeployStrategy::BlueGreen => "blue-green",
        }
    }
}

/// Deployment result
#[derive(Debug, Clone)]
pub struct DeployResult {
    pub success: bool,
    pub message: String,
    pub health_check_passed: bool,
    pub backup_created: bool,
}
