use serde::{Deserialize, Serialize};

/// AI tool call execution status. Stored as `"pending"`, `"running"`, `"success"`,
/// `"failed"`, or `"retrying"`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ToolCallStatus {
    Pending,
    Running,
    Success,
    Failed,
    Retrying,
}

impl std::fmt::Display for ToolCallStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ToolCallStatus::Pending => write!(f, "pending"),
            ToolCallStatus::Running => write!(f, "running"),
            ToolCallStatus::Success => write!(f, "success"),
            ToolCallStatus::Failed => write!(f, "failed"),
            ToolCallStatus::Retrying => write!(f, "retrying"),
        }
    }
}

impl std::str::FromStr for ToolCallStatus {
    type Err = &'static str;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "pending" => Ok(ToolCallStatus::Pending),
            "running" => Ok(ToolCallStatus::Running),
            "success" => Ok(ToolCallStatus::Success),
            "failed" => Ok(ToolCallStatus::Failed),
            "retrying" => Ok(ToolCallStatus::Retrying),
            _ => Err("unknown tool call status"),
        }
    }
}

pub use ai_session::Entity as AiSession;
pub use ai_tool_auth::Entity as AiToolAuth;
pub use ai_tool_call::Entity as AiToolCall;

pub mod ai_session;
pub mod ai_tool_auth;
pub mod ai_tool_call;
