//! Templates for `gize make app`: the full file set of an application module (ADR-005).
//!
//! The skeleton compiles as-is (a placeholder `index` route). `gize make model` and
//! `gize make crud` later flesh out `model.rs`, `repository.rs`, `service.rs`, etc.

/// `mod.rs`: declares the module's files and re-exports its router.
pub fn mod_rs(module: &str) -> String {
    format!(
        r#"//! The `{module}` module, generated by `gize make app`.
//!
//! Flesh it out with `gize make model` and `gize make crud`.

pub mod dto;
pub mod error;
pub mod handler;
pub mod model;
pub mod repository;
pub mod service;
pub mod routes;

#[cfg(test)]
mod tests;

pub use routes::routes;
"#
    )
}

/// `routes.rs`: the module's Axum router. Merged into `app::routes()`.
pub fn routes_rs(module: &str) -> String {
    format!(
        r#"use axum::Router;
use axum::routing::get;

use super::handler;
use crate::state::AppState;

/// Routes for the `{module}` module. `gize make crud` extends this with CRUD endpoints.
pub fn routes() -> Router<AppState> {{
    Router::new().route("/{module}", get(handler::index))
}}
"#
    )
}

/// `handler.rs`: HTTP handlers. Starts with a placeholder index handler.
pub fn handler_rs(module: &str) -> String {
    format!(
        r#"//! HTTP handlers for the `{module}` module.

/// Placeholder handler so the module is reachable immediately after `gize make app`.
/// `gize make crud` replaces this with list/create/show/update/delete handlers.
pub async fn index() -> &'static str {{
    "{module} module"
}}
"#
    )
}

/// `model.rs` placeholder. Filled in by `gize make model`.
pub fn model_placeholder_rs(module: &str) -> String {
    format!(
        "//! Domain model for the `{module}` module.\n//!\n//! Define fields with \
         `gize make model <Name> field:Type ...`.\n"
    )
}

/// `dto.rs` placeholder.
pub fn dto_rs(module: &str) -> String {
    format!("//! Request/response DTOs for the `{module}` module.\n")
}

/// `repository.rs` placeholder.
pub fn repository_rs(module: &str) -> String {
    format!("//! SQL persistence for the `{module}` module (SQLx).\n")
}

/// `service.rs` placeholder.
pub fn service_rs(module: &str) -> String {
    format!("//! Business logic for the `{module}` module.\n")
}

/// `error.rs` placeholder.
pub fn error_rs(module: &str) -> String {
    format!("//! Error types for the `{module}` module.\n")
}

/// `tests.rs`: a placeholder test so the module ships with a green test from day one.
pub fn tests_rs(module: &str) -> String {
    format!(
        "//! Tests for the `{module}` module.\n\n#[test]\nfn placeholder() {{\n    \
         // Add real tests as the module grows.\n}}\n"
    )
}
