use super::{Line, LineBody, LineSite, SiteCoordinate};
use crate::bounded::Capping;
use crate::request::Door;
use crate::token::CoordinateRole;
const fn coordinate_role_word(role: CoordinateRole) -> &'static str {
match role {
CoordinateRole::Byte => "byte",
CoordinateRole::SemanticOrigin => "semantic-origin position",
}
}
fn body_clause(body: LineBody) -> String {
let (further, capping) = match body {
LineBody::SingleCause => return String::new(),
LineBody::Body { further, capping } => (further, capping),
};
let more = if further > 0 {
format!(" (and {further} further established issues)")
} else {
String::new()
};
let kept = match capping {
Capping::Complete => String::new(),
Capping::Truncated { omitted } => format!(
" (every issue was established; {omitted} of them do not fit the declared issue bound)"
),
};
format!("{more}{kept}")
}
fn site_clause(site: LineSite) -> String {
match site {
LineSite::WholeDeclaration => String::new(),
LineSite::At(SiteCoordinate::Resolved(coordinate)) => {
let word = coordinate_role_word(coordinate.role);
let position = coordinate.position;
format!(" (at {word} {position})")
}
LineSite::At(SiteCoordinate::NotReached(refusal)) => format!(" ({refusal})"),
}
}
#[must_use]
pub fn composed(door: &Door, line: &Line<'_>, site: LineSite) -> String {
let prefix = door.prefix();
let class = line.class.described();
let first = line.first;
let stated_body = body_clause(line.body);
let stated_site = site_clause(site);
format!("{prefix}: {class}: {first}{stated_body}{stated_site}")
}
pub(crate) fn witnessed(line: &str, capping: Capping) -> String {
match capping {
Capping::Complete => line.to_owned(),
Capping::Truncated { omitted } => format!(
"{line} (the related set was capped at the declared issue bound: one identity over the \
complete body is carried and {omitted} per-issue identities are not)"
),
}
}