use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum KnowledgePolicyLifecycleInput {
Active,
Proposed,
Accepted,
Implemented,
Deferred,
Rejected,
Withdrawn,
Deprecated,
Superseded,
Archived,
Historical,
Unknown,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum KnowledgePolicyAuthorityDomainInput {
CurrentImplementation,
NormativeIntent,
Decision,
Operations,
Governance,
HistoricalRecord,
Unknown,
}
#[derive(Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct KnowledgePolicyTargetInput {
pub path: String,
pub content_hash: String,
#[serde(default)]
#[schemars(with = "[u32; 2]")]
pub unit_byte_range: Option<[u32; 2]>,
#[serde(default)]
pub unit_hash: Option<String>,
}
impl std::fmt::Debug for KnowledgePolicyTargetInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("KnowledgePolicyTargetInput { redacted }")
}
}
#[derive(Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct KnowledgePolicyEvidenceInput {
pub rule_id: String,
#[serde(default)]
pub knowledge: Option<KnowledgePolicyTargetInput>,
#[serde(default)]
pub code_path: Option<String>,
}
impl std::fmt::Debug for KnowledgePolicyEvidenceInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("KnowledgePolicyEvidenceInput { redacted }")
}
}
#[derive(Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct KnowledgePolicyEntryInput {
pub entry_id: String,
pub target: KnowledgePolicyTargetInput,
pub lifecycle: KnowledgePolicyLifecycleInput,
#[serde(default)]
pub authority_domain: Option<KnowledgePolicyAuthorityDomainInput>,
#[serde(default)]
pub superseded_by: Option<KnowledgePolicyTargetInput>,
#[serde(default)]
pub evidence: Vec<KnowledgePolicyEvidenceInput>,
pub justification_code: String,
}
impl std::fmt::Debug for KnowledgePolicyEntryInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("KnowledgePolicyEntryInput { redacted }")
}
}
#[derive(Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(tag = "operation", rename_all = "snake_case", deny_unknown_fields)]
pub enum KnowledgePolicyMutationInput {
Upsert {
entry: KnowledgePolicyEntryInput,
},
Remove {
entry_id: String,
expected_target: KnowledgePolicyTargetInput,
},
}
impl std::fmt::Debug for KnowledgePolicyMutationInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("KnowledgePolicyMutationInput { redacted }")
}
}
#[derive(Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct KnowledgePolicyActionInput {
pub action_id: String,
pub mutation: KnowledgePolicyMutationInput,
}
impl std::fmt::Debug for KnowledgePolicyActionInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("KnowledgePolicyActionInput { redacted }")
}
}
#[derive(Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct CurateKnowledgeInput {
pub actions: Vec<KnowledgePolicyActionInput>,
pub if_source_review_hash: String,
pub if_manifest_digest: String,
pub if_policy_digest: String,
#[serde(default)]
pub idempotency_key: Option<String>,
#[serde(default)]
pub apply: bool,
#[schemars(required)]
pub project: Option<String>,
}
impl std::fmt::Debug for CurateKnowledgeInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CurateKnowledgeInput")
.field("action_count", &self.actions.len())
.field("apply", &self.apply)
.field("has_idempotency_key", &self.idempotency_key.is_some())
.finish()
}
}