use async_trait::async_trait;
use log::info;
use pib_client::PibClient;
use pib_service_api_types::body::by_id_or_alias::meeting::by_id::agenda_item::by_id::consultation::{
Consultation, ConsultationParentId, UpdateConsultation,
};
use pib_service_core_types::{AgendaItemId, DataItem};
use crate::item::{GetableItem, PlaceableItem, UpdatableItem};
#[async_trait(?Send)]
impl GetableItem<ConsultationParentId, AgendaItemId, Consultation> for Consultation {
async fn get<C: PibClient>(
client: &C,
ConsultationParentId {
body_id,
meeting_id,
}: ConsultationParentId,
agenda_item_id: AgendaItemId,
) -> Result<DataItem<ConsultationParentId, AgendaItemId, Consultation>, C::ClientError> {
Ok(client
.body_by_id_or_alias_meeting_by_id_agenda_item_by_id_consultation_get(
body_id,
meeting_id,
agenda_item_id,
)
.await?)
}
}
#[async_trait(?Send)]
impl PlaceableItem<ConsultationParentId, AgendaItemId, Consultation> for Consultation {
async fn place<C: PibClient>(
client: &C,
ConsultationParentId {
body_id,
meeting_id,
}: ConsultationParentId,
agenda_item_id: AgendaItemId,
new_item: Consultation,
) -> Result<DataItem<ConsultationParentId, AgendaItemId, Consultation>, C::ClientError> {
let created_item = client
.body_by_id_or_alias_meeting_by_id_agenda_item_by_id_consultation_put(
body_id,
meeting_id,
agenda_item_id,
new_item,
)
.await?;
info!("Created a new consultation: {created_item:?}");
Ok(created_item)
}
}
#[async_trait(?Send)]
impl UpdatableItem<ConsultationParentId, AgendaItemId, Consultation, UpdateConsultation>
for Consultation
{
async fn update<C: PibClient>(
client: &C,
ConsultationParentId {
body_id,
meeting_id,
}: ConsultationParentId,
agenda_item_id: AgendaItemId,
update_item: UpdateConsultation,
) -> Result<DataItem<ConsultationParentId, AgendaItemId, Consultation>, C::ClientError> {
let updated_item = client
.body_by_id_or_alias_meeting_by_id_agenda_item_by_id_consultation_patch(
body_id,
meeting_id,
agenda_item_id,
update_item,
)
.await?;
info!("Updated agenda item: {updated_item:?}");
Ok(updated_item)
}
}