//! news‑backend – a minimal Rocket service that returns a static
//! privacy‑summary JSON payload.
//!
//! The code demonstrates the proper way to declare a serialisable
//! struct, expose it via a GET route, and launch the Rocket instance.

use rocket::serde::{json::Json, Serialize}; // Rocket re‑exports serde::Serialize
use rocket::{get, launch, routes};

/// The data model that will be serialized to JSON.
///
/// * `policy` – the SPDX license identifier (static string).  
/// * `description` – a human‑readable description of the service.  
/// * `data_collected` – a list of data categories (empty for this demo).  
/// * `rights` – GDPR‑style rights offered to the user.
#[derive(Debug, Serialize)]
struct PrivacySummary {
    policy: String,
    description: String,
    data_collected: Vec<String>,
    rights: Vec<String>,
}

/// GET `/privacy-summary` – returns the static `PrivacySummary` as JSON.
///
/// The return type **must** be `Json<PrivacySummary>` because Rocket’s
/// `Responder` implementation for JSON is defined only for types that
/// implement `Serialize`.
#[get("/privacy-summary")]
fn privacy_summary() -> Json<PrivacySummary> {
    // Build the struct inline; `into()` converts the string literals
    // into owned `String`s, and `vec![]` creates empty vectors.
    Json(PrivacySummary {
        policy: "SPDX-2.2".into(),
        description: "Zero‑profiling news aggregator – no cookies, no IP logs.".into(),
        data_collected: vec![], // No data collected in this demo
        rights: vec!["right to object".into(), "right to access".into()],
    })
}

/// Launch the Rocket application.
///
/// `rocket::build()` creates a new instance, and `mount` attaches the
/// route(s) under the given base path (`"/"` in this case).  
/// The macro `routes![privacy_summary]` expands to a slice containing the
/// route metadata generated by the `#[get]` attribute.
#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![privacy_summary])
}
