use std::path::Path;
use crate::{
inspect::RequestView,
store::{self, Shown},
types::RequestId,
};
use super::HumanClaim;
pub struct Review {
pub exact: RequestView,
pub owner: RequestView,
}
pub async fn request(state: &Path, id: &RequestId) -> Result<RequestView, String> {
request_with(state, id, Shown::Requests).await
}
pub(super) async fn request_with(
state: &Path,
id: &RequestId,
shown: Shown,
) -> Result<RequestView, String> {
store::read_request_by_id(state, id, shown).await
}
pub async fn read(state: &Path, id: &RequestId) -> Result<Review, String> {
resolve(state, request(state, id).await?).await
}
pub async fn resolve(state: &Path, exact: RequestView) -> Result<Review, String> {
let owner = store::read_review_owner(state, &exact).await?;
Ok(Review { exact, owner })
}
pub async fn claim_is_current(state: &Path, claim: &HumanClaim) -> Result<bool, String> {
Ok(
store::read_optional_request(state, &claim.request_id, Shown::Requests)
.await?
.is_some_and(|view| view.claim.as_ref() == Some(claim)),
)
}