use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TermStoreValueDto {
Integer { value: i64 },
Real { value: f64 },
String { value: String },
Boolean { value: bool },
Uninstantiated,
Reference { term_id: String },
List { items: Vec<TermStoreValueDto> },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateTermStoreRequest {
pub tenant_id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub owner_id: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TermStoreSessionResponse {
pub session_id: String,
pub tenant_id: String,
pub term_count: u64,
pub variable_count: u64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CreateStoreTermRequest {
pub sort_id: String,
#[serde(default)]
pub features: BTreeMap<String, TermStoreValueDto>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateVariableRequest {
pub sort_id: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CreateTermResponse {
pub term_id: String,
pub is_variable: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BindVariableRequest {
pub variable_id: String,
pub target_id: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BindVariableResponse {
pub success: bool,
pub variable_id: String,
pub bound_to: String,
pub trail_length: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnifyTermsRequest {
pub term1_id: String,
pub term2_id: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UnifyTermsResponse {
pub success: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
pub trail_length: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub unified_term_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DereferenceRequest {
pub term_id: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DereferenceResponse {
pub original_id: String,
pub dereferenced_id: String,
pub is_bound: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SetFeatureRequest {
pub term_id: String,
pub feature_name: String,
pub value: TermStoreValueDto,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SetFeatureResponse {
pub success: bool,
pub term_id: String,
pub feature_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetStoreTermRequest {
pub term_id: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GetStoreTermResponse {
pub term_id: String,
pub sort_id: String,
#[serde(default)]
pub features: BTreeMap<String, TermStoreValueDto>,
pub is_variable: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bound_to: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MarkTermStoreRequest {}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MarkTermStoreResponse {
pub marker_index: u64,
pub trail_length: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BacktrackTermStoreRequest {
pub marker_index: u64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BacktrackTermStoreResponse {
pub success: bool,
pub undone_entries: u64,
pub current_trail_length: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateRuleStoreRequest {
pub tenant_id: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RuleStoreResponse {
pub store_id: String,
pub tenant_id: String,
pub rule_count: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RuleConstraintDto {
Sort {
var_name: String,
sort_id: String,
},
Feature {
var_name: String,
feature_name: String,
value: TermStoreValueDto,
},
Equal {
var1: String,
var2: String,
},
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RuleClauseDto {
#[serde(default)]
pub constraints: Vec<RuleConstraintDto>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AssertRuleRequest {
pub head: RuleClauseDto,
#[serde(default)]
pub body: Vec<RuleClauseDto>,
#[serde(default)]
pub assert_first: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AssertRuleResponse {
pub rule_id: String,
pub rule_count: u64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RetractRuleRequest {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rule_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pattern: Option<RuleClauseDto>,
#[serde(default)]
pub retract_all: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RetractRuleResponse {
pub retracted_count: u64,
#[serde(default)]
pub retracted_ids: Vec<String>,
pub remaining_count: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FindRulesRequest {
pub pattern: RuleClauseDto,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RuleDto {
pub id: String,
pub head: RuleClauseDto,
#[serde(default)]
pub body: Vec<RuleClauseDto>,
pub is_fact: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FindRulesResponse {
#[serde(default)]
pub matching_rules: Vec<RuleDto>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MarkRuleStoreRequest {}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MarkRuleStoreResponse {
pub marker_index: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UndoRuleStoreRequest {
pub marker_index: u64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UndoRuleStoreResponse {
pub success: bool,
pub rule_count: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EvalBuiltinRequest {
pub function_name: String,
pub arguments: Vec<TermStoreValueDto>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum EvalBuiltinResponse {
Success { result: TermStoreValueDto },
SuccessUnit,
Failure,
Residuate { blocking_arg_index: u64 },
Error { message: String },
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ListEvalFunctionsQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct EvalFunctionInfoDto {
pub name: String,
pub category: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub arity: Option<u64>,
pub description: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ListEvalFunctionsResponse {
#[serde(default)]
pub functions: Vec<EvalFunctionInfoDto>,
}