use std::sync::Arc;

use dashmap::DashMap;
use uuid::Uuid;
use common_contracts::observability::TaskProgress;

use crate::config::AppConfig;
use crate::yfinance::YFinanceDataProvider;

#[derive(Clone)]
pub struct AppState {
    pub tasks: Arc<DashMap<Uuid, TaskProgress>>,
    pub config: Arc<AppConfig>,
    pub yfinance_provider: Arc<YFinanceDataProvider>,
}

impl AppState {
    pub fn new(config: AppConfig) -> Self {
        let provider = Arc::new(YFinanceDataProvider::new(config.yfinance_enabled));

        Self {
            tasks: Arc::new(DashMap::new()),
            config: Arc::new(config),
            yfinance_provider: provider,
        }
    }
}
