//! Template routes module for handling template page requests

#![allow(dead_code)]

use std::sync::Arc;

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

use crate::handlers::template::*;
use crate::template::TemplateService;

/// Create template routes
#[allow(dead_code)]
pub fn create_template_routes(template_service: Arc<TemplateService>) -> Router {
    Router::new()
        // Main template page route - handles /page:content-name
        .route("/page/{content_name}", get(serve_template_page))
        // API routes for template management
        .route("/api/template/{content_name}", get(api_template_page))
        .route("/api/template/list/{lang}", get(list_template_content))
        .route("/api/template/languages", get(get_template_languages))
        .route("/api/template/stats", get(get_template_stats))
        .route("/api/template/cache/clear", post(clear_template_cache))
        .route("/api/template/reload", post(reload_templates))
        .route(
            "/api/template/exists/{content_name}",
            get(check_template_exists),
        )
        .route(
            "/api/template/config/{content_name}",
            get(get_template_config),
        )
        .route("/api/template/health", get(template_health_check))
        .with_state(template_service)
}

/// Create template routes with custom prefix
#[allow(dead_code)]
pub fn create_template_routes_with_prefix(
    template_service: Arc<TemplateService>,
    prefix: &str,
) -> Router {
    let prefix = prefix.trim_matches('/');

    Router::new()
        // Main template page route with custom prefix
        .route(
            &format!("/{}/page/{content_name}", prefix),
            get(serve_template_page),
        )
        // API routes with custom prefix
        .route(
            &format!("/{}/api/template/{content_name}", prefix),
            get(api_template_page),
        )
        .route(
            &format!("/{}/api/template/list/{lang}", prefix),
            get(list_template_content),
        )
        .route(
            &format!("/{}/api/template/languages", prefix),
            get(get_template_languages),
        )
        .route(
            &format!("/{}/api/template/stats", prefix),
            get(get_template_stats),
        )
        .route(
            &format!("/{}/api/template/cache/clear", prefix),
            post(clear_template_cache),
        )
        .route(
            &format!("/{}/api/template/reload", prefix),
            post(reload_templates),
        )
        .route(
            &format!("/{}/api/template/exists/{content_name}", prefix),
            get(check_template_exists),
        )
        .route(
            &format!("/{}/api/template/config/{content_name}", prefix),
            get(get_template_config),
        )
        .route(
            &format!("/{}/api/template/health", prefix),
            get(template_health_check),
        )
        .with_state(template_service)
}
