Skip to main content

poe2_agent/
wiki.rs

1//! PoE2 Wiki scraper and cache.
2//!
3//! Fetches and caches data from the Path of Exile 2 wiki.
4
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7use std::path::PathBuf;
8use thiserror::Error;
9
10#[derive(Error, Debug)]
11pub enum WikiError {
12    #[error("HTTP error: {0}")]
13    Http(#[from] reqwest::Error),
14
15    #[error("Parse error: {0}")]
16    Parse(String),
17
18    #[error("Cache error: {0}")]
19    Cache(String),
20
21    #[error("Not found: {0}")]
22    NotFound(String),
23}
24
25/// Wiki client with caching.
26#[allow(dead_code)]
27pub struct WikiClient {
28    client: reqwest::Client,
29    cache_dir: PathBuf,
30    base_url: String,
31}
32
33/// Skill gem data from the wiki.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct SkillGem {
36    pub name: String,
37    pub tags: Vec<String>,
38    pub description: String,
39    pub base_damage: Option<DamageInfo>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct DamageInfo {
44    pub min: f64,
45    pub max: f64,
46    pub damage_type: String,
47}
48
49/// Unique item data from the wiki.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct UniqueItem {
52    pub name: String,
53    pub base_type: String,
54    pub modifiers: Vec<String>,
55    pub requirements: HashMap<String, i32>,
56}
57
58impl WikiClient {
59    /// Create a new wiki client.
60    pub fn new(cache_dir: PathBuf) -> Self {
61        Self {
62            client: reqwest::Client::new(),
63            cache_dir,
64            base_url: "https://www.poewiki.net/wiki/".to_owned(),
65        }
66    }
67
68    /// Fetch skill gem data.
69    pub async fn get_skill(&self, name: &str) -> Result<SkillGem, WikiError> {
70        // TODO: Check cache first
71        // TODO: Fetch from wiki API
72        // TODO: Parse and cache result
73
74        tracing::debug!("Fetching skill: {}", name);
75
76        // Placeholder
77        Err(WikiError::NotFound(name.to_owned()))
78    }
79
80    /// Fetch unique item data.
81    pub async fn get_unique(&self, name: &str) -> Result<UniqueItem, WikiError> {
82        // TODO: Implement
83        tracing::debug!("Fetching unique: {}", name);
84        Err(WikiError::NotFound(name.to_owned()))
85    }
86
87    /// Search for items/skills matching a query.
88    pub async fn search(&self, query: &str) -> Result<Vec<String>, WikiError> {
89        // TODO: Implement wiki search
90        tracing::debug!("Searching wiki for: {}", query);
91        Ok(Vec::new())
92    }
93
94    /// Clear the cache.
95    pub fn clear_cache(&self) -> Result<(), WikiError> {
96        // TODO: Clear cache directory
97        Ok(())
98    }
99}