// 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 crate::Result;
use pib_service_inventory::Meeting;
use std::sync::Arc;
use uuid::Uuid;

use axum::{
    Json,
    extract::{Path, State},
};
use pib_service_api_types::body::meeting::GetMeetingResponseBody;

use crate::ServiceState;

pub async fn get(
    State(service_state): State<Arc<ServiceState>>,
    Path((body_id, meeting_id)): Path<(Uuid, Uuid)>,
) -> Result<Json<GetMeetingResponseBody>> {
    let mut inventory = service_state.inventory_provider.get_inventory().await?;
    let Meeting {
        id,
        body,
        created,
        modified,
        organization,
        start,
        end,
        name,
        meeting_state,
        agenda_item: _,
        keyword: _,
        license,
        web,
    } = inventory
        .get_meeting(&body_id.to_string(), &meeting_id.to_string())
        .await?;
    Ok(Json(GetMeetingResponseBody(
        pib_service_api_types::body::meeting::Meeting {
            id,
            body_id: body,
            organization_id: organization,
            created,
            modified,
            name: name.map(Into::into),
            meeting_state: Some(meeting_state.into()),
            start,
            end,
            license,
            web,
        },
    )))
}
