syntax = "proto3";

package macp.v1;

// PolicyDescriptor — the canonical wire format for governance policy definitions.
// See RFC-MACP-0012 for normative semantics.
message PolicyDescriptor {
  // Unique policy identifier (e.g., "policy.fraud.majority-veto").
  string policy_id = 1;

  // Target mode identifier (e.g., "macp.mode.decision.v1") or "*" for mode-agnostic.
  string mode = 2;

  // Human-readable description of the policy's governance rules.
  string description = 3;

  // JSON-encoded governance rules per the target mode's rule schema.
  // The structure of this JSON is defined by the mode-specific rule JSON Schema
  // (e.g., schemas/json/policy/decision-rules.schema.json for Decision Mode).
  bytes rules = 4;

  // Version of the rule schema used (currently 1).
  uint32 schema_version = 5;

  int64 registered_at_unix_ms = 6; // Unix epoch milliseconds; set by the runtime, ignored in RegisterPolicyRequest.
}

// Policy registry capability advertised during Initialize.
message PolicyRegistryCapability {
  bool register_policy = 1;
  bool list_policies = 2;
  bool list_changed = 3;
}

// ── Registration lifecycle RPCs ─────────────────────────────────────

message RegisterPolicyRequest {
  PolicyDescriptor policy_descriptor = 1;
}

message RegisterPolicyResponse {
  bool ok = 1;
  string error = 2;
}

message UnregisterPolicyRequest {
  string policy_id = 1;
}

message UnregisterPolicyResponse {
  bool ok = 1;
  string error = 2;
}

message GetPolicyRequest {
  string policy_id = 1;
}

message GetPolicyResponse {
  PolicyDescriptor policy_descriptor = 1;
}

message ListPoliciesRequest {
  // Optional filter: only return policies targeting this mode.
  // Empty returns all registered policies.
  string mode = 1;
}

message ListPoliciesResponse {
  repeated PolicyDescriptor descriptors = 1;
}

message WatchPoliciesRequest {}

message WatchPoliciesResponse {
  repeated PolicyDescriptor descriptors = 1;
  int64 observed_at_unix_ms = 2;
}
