mod provider_cache;
mod history;
mod companies;
mod configs;
mod market_data;
mod system;
mod session_data;
mod templates;

use crate::AppState;
use axum::{
    routing::{get, post},
    Router,
};

pub fn create_router(_state: AppState) -> Router<AppState> {
    let router: Router<AppState> = Router::new()
        // System
        .route("/health", get(system::get_health))
        .route("/api/v1/system/history", axum::routing::delete(system::clear_history))
        // Configs
        .route(
            "/api/v1/configs/llm_providers",
            get(configs::get_llm_providers_config).put(configs::update_llm_providers_config),
        )
        // .route(
        //     "/api/v1/configs/analysis_template_sets",
        //     get(configs::get_analysis_template_sets).put(configs::update_analysis_template_sets),
        // )
        .route(
            "/api/v1/configs/data_sources",
            get(configs::get_data_sources_config).put(configs::update_data_sources_config),
        )
        // Companies
        .route("/companies/{symbol}", get(companies::get_company_by_symbol))
        .route(
            "/companies/{symbol}/providers/{provider_id}/status",
            get(companies::get_provider_status).put(companies::update_provider_status),
        )
        // Market Data
        .route(
            "/market-data/financial-statements/{symbol}",
            get(market_data::get_financials_by_symbol),
        )
        // Analysis Results (REMOVED)
        // .route(
        //     "/analysis-results",
        //     post(analysis::create_analysis_result).get(analysis::get_analysis_results),
        // )
        // .route(
        //     "/analysis-results/{id}",
        //     get(analysis::get_analysis_result_by_id),
        // )
        // Session Data
        .route(
            "/session-data",
            post(session_data::insert_session_data),
        )
        .route(
            "/session-data/{request_id}",
            get(session_data::get_session_data).delete(session_data::delete_session_data),
        )
        // Provider Cache
        .route(
            "/provider-cache",
            get(provider_cache::get_cache).post(provider_cache::set_cache),
        )
        // Workflow History (NEW)
        .route(
            "/history",
            post(history::create_workflow_history).get(history::get_workflow_histories),
        )
        .route(
            "/history/{request_id}",
            get(history::get_workflow_history_by_id),
        )
        // Templates (NEW)
        .route(
            "/api/v1/templates",
            get(templates::get_templates),
        )
        .route(
            "/api/v1/templates/{id}",
            get(templates::get_template_by_id).put(templates::update_template).delete(templates::delete_template),
        );

    router
}
