use crate::evaluation::operations::VetoType;
use crate::planning::semantics::LiteralValue;
use crate::OperationResult;
use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct Target {
pub op: TargetOp,
pub outcome: Option<OperationResult>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
pub enum TargetOp {
Eq,
Neq,
Lt,
Lte,
Gt,
Gte,
}
impl Target {
pub fn value(value: LiteralValue) -> Self {
Self {
op: TargetOp::Eq,
outcome: Some(OperationResult::Value(Box::new(value))),
}
}
pub fn veto(message: Option<String>) -> Self {
Self {
op: TargetOp::Eq,
outcome: Some(OperationResult::Veto(VetoType::UserDefined { message })),
}
}
pub fn any_veto() -> Self {
Self::veto(None)
}
pub fn any_value() -> Self {
Self {
op: TargetOp::Eq,
outcome: None,
}
}
pub fn with_op(op: TargetOp, outcome: OperationResult) -> Self {
Self {
op,
outcome: Some(outcome),
}
}
pub fn format(&self) -> String {
let op_str = match self.op {
TargetOp::Eq => "=",
TargetOp::Neq => "is not",
TargetOp::Lt => "<",
TargetOp::Lte => "<=",
TargetOp::Gt => ">",
TargetOp::Gte => ">=",
};
let value_str = match &self.outcome {
None => "any".to_string(),
Some(OperationResult::Value(v)) => v.to_string(),
Some(OperationResult::Veto(reason)) => format!("veto({reason})"),
};
format!("{} {}", op_str, value_str)
}
}