use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum BrowserType {
    Chrome,
    Firefox,
    Safari,
    Edge,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum SessionStatus {
    Starting,
    Running,
    Idle,
    Error,
    Closed,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BrowserCommand {
    pub action: BrowserAction,
    pub parameters: std::collections::HashMap<String, serde_json::Value>,
    pub timeout_ms: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum BrowserAction {
    Navigate { url: String },
    Click { selector: String },
    Type { selector: String, text: String },
    Screenshot { path: Option<String> },
    ExecuteScript { script: String },
    WaitForElement { selector: String, timeout_ms: u32 },
    GetTitle {},
    GetUrl {},
    Refresh {},
    Back {},
    Forward {},
    GetText { selector: String },
    GetAttribute { selector: String, attribute: String },
    ScrollTo { selector: Option<String> },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommandResult {
    pub success: bool,
    pub data: serde_json::Value,
    pub error: Option<String>,
    pub execution_time_ms: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionStats {
    pub total_sessions: usize,
    pub running_sessions: usize,
    pub idle_sessions: usize,
    pub error_sessions: usize,
    pub browser_type_counts: std::collections::HashMap<String, usize>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BrowserSession {
    pub id: String,
    pub browser_type: BrowserType,
    pub agent_id: String,
    pub status: SessionStatus,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub last_activity: chrono::DateTime<chrono::Utc>,
    pub url: Option<String>,
    pub title: Option<String>,
    pub chromiumoxide_handle: Option<String>,
}
