// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

use std::sync::Arc;

use crate::Result;
use axum::{
    Json,
    extract::{Path, State},
};
use pib_service_api_types::body::{Body, GetBodyByBodyIdResponseBody};
use uuid::Uuid;

use crate::ServiceState;

pub(crate) mod meeting;

pub(crate) async fn get(
    State(service_state): State<Arc<ServiceState>>,
    Path(body_id): Path<Uuid>,
) -> Result<Json<GetBodyByBodyIdResponseBody>> {
    let mut inventory = service_state.inventory_provider.get_inventory().await?;

    let pib_service_inventory::Body {
        id,
        created,
        modified,
        short_name,
        name,
        website,
        license,
        license_valid_since,
        oparl_since,
        ags,
        rgs,
        contact_email,
        contact_name,
        classification,
    } = inventory.get_body(&body_id.to_string()).await?;

    let body = Body {
        id,
        created,
        modified,
        short_name,
        name,
        website,
        license,
        license_valid_since,
        oparl_since,
        ags,
        rgs,
        contact_email,
        contact_name,
        classification,
    };

    Ok(Json(GetBodyByBodyIdResponseBody(body)))
}
