package adk

// QueryInput represents input parameters for the Query tool.
//
// Query retrieves knowledge with lens-based conflict resolution.
type QueryInput struct {
	// Subject entity to query (e.g., "auth/jwt")
	Subject string `json:"subject"`

	// Predicate relation to query (e.g., "signing_algorithm")
	Predicate string `json:"predicate"`

	// Lens for conflict resolution (consensus, authority, recency, constraints)
	Lens string `json:"lens,omitempty"`

	// Lifecycle filter (proposed, approved, deprecated)
	Lifecycle string `json:"lifecycle,omitempty"`

	// Minimum confidence threshold (0.0-1.0)
	MinConfidence float32 `json:"min_confidence,omitempty"`

	// Time-travel query (ISO8601 timestamp)
	AsOf string `json:"as_of,omitempty"`
}

// QueryOutput represents the result of a Query operation.
//
// CRITICAL: QueryID is required for audit trail.
type QueryOutput struct {
	// The resolved value
	Value any `json:"value"`

	// Confidence score (0.0-1.0)
	Confidence float32 `json:"confidence"`

	// Lifecycle stage of the resolved value
	Lifecycle string `json:"lifecycle"`

	// Source provenance
	Sources []Source `json:"sources"`

	// CRITICAL: Unique query ID for audit trail
	QueryID string `json:"query_id"`

	// Error message if query failed
	Error string `json:"error,omitempty"`
}

// Source represents provenance information for an assertion.
type Source struct {
	// Content-addressed hash of the assertion
	Hash string `json:"hash"`

	// Hash of the source evidence
	SourceHash string `json:"source_hash"`

	// Weight in resolution (0.0-1.0)
	Weight float32 `json:"weight"`
}

// AssertInput represents input parameters for the Assert tool.
//
// Used by Research Agent and Human Supervisor to store knowledge.
type AssertInput struct {
	// Entity being described
	Subject string `json:"subject"`

	// Relation being asserted
	Predicate string `json:"predicate"`

	// Value being claimed
	Object any `json:"object"`

	// BLAKE3 hash of evidence
	SourceHash string `json:"source_hash"`

	// Certainty level (0.0-1.0)
	Confidence float32 `json:"confidence"`

	// Lifecycle stage (proposed, under_review, approved)
	Lifecycle string `json:"lifecycle,omitempty"`

	// Hash of assertion being updated
	ParentHash string `json:"parent_hash,omitempty"`

	// Metadata and constraints
	Meta *AssertMeta `json:"meta,omitempty"`
}

// AssertMeta contains metadata and constraints for assertions.
type AssertMeta struct {
	// Forbidden alternative (for negative constraints)
	ForbiddenAlternative string `json:"forbidden_alternative,omitempty"`

	// Reason for the constraint
	Reason string `json:"reason,omitempty"`
}

// AssertOutput represents the result of an Assert operation.
type AssertOutput struct {
	// Content-addressed hash of the created assertion
	Hash string `json:"hash"`

	// Success flag
	Success bool `json:"success"`

	// Error message if assertion failed
	Error string `json:"error,omitempty"`
}

// ConstraintCheckInput represents input for the ConstraintCheck tool.
//
// Used by Implementation Agent for pre-flight validation.
type ConstraintCheckInput struct {
	// Domain context (e.g., "python_http", "auth_jwt")
	Context string `json:"context"`
}

// ConstraintCheckOutput represents the result of a constraint check.
type ConstraintCheckOutput struct {
	// List of constraints for the given context
	Constraints []Constraint `json:"constraints"`
}

// Constraint represents a must-use or forbidden pattern.
type Constraint struct {
	// Subject entity
	Subject string `json:"subject"`

	// Required pattern to use
	MustUse string `json:"must_use,omitempty"`

	// Forbidden pattern
	Forbidden string `json:"forbidden,omitempty"`

	// Reason for the constraint
	Reason string `json:"reason"`
}

// TraceInput represents input for the Trace tool.
//
// Used by On-Call SRE and Human Supervisor for audit investigation.
type TraceInput struct {
	// Agent ID to trace
	AgentID string `json:"agent_id"`

	// Start time (ISO8601 or relative like "-6h")
	From string `json:"from"`

	// End time (default: now)
	To string `json:"to,omitempty"`

	// Filter by subject pattern (e.g., "auth/*")
	Subject string `json:"subject,omitempty"`
}

// TraceOutput represents the result of a Trace operation.
type TraceOutput struct {
	// List of queries made by the agent
	Queries []QueryTrace `json:"queries"`
}

// QueryTrace represents a single query in an audit trail.
type QueryTrace struct {
	// Unique query identifier
	QueryID string `json:"query_id"`

	// Timestamp when the query was made
	Timestamp string `json:"timestamp"`

	// Subject queried
	Subject string `json:"subject"`

	// Predicate queried
	Predicate string `json:"predicate"`

	// Lens used for resolution
	Lens string `json:"lens"`

	// Result returned
	Result string `json:"result"`

	// Confidence of the result
	Confidence float32 `json:"confidence"`

	// Assertions that contributed to the result
	Contributing []string `json:"contributing_assertions"`
}

// SupersedeInput represents input for the Supersede tool.
//
// Used by Human Supervisor to correct errors with cascade tracking.
type SupersedeInput struct {
	// Hash of assertion to supersede (hex-encoded, 32 bytes)
	Hash string `json:"hash"`

	// Type of supersession (Invalidate, Temporal, Refinement, RequiresReview, Additive)
	Type string `json:"type"`

	// Reason for superseding (required for audit trail)
	Reason string `json:"reason"`

	// Hash of replacement assertion (hex-encoded, optional)
	NewHash string `json:"new_hash,omitempty"`

	// Public key of the agent creating the supersession (hex-encoded, 32 bytes)
	AgentID string `json:"agent_id"`

	// Signature over the supersession content (hex-encoded, 64 bytes)
	Signature string `json:"signature"`
}

// SupersedeOutput represents the result of a Supersede operation.
type SupersedeOutput struct {
	// Success flag
	Success bool `json:"success"`

	// Hash of the target assertion that was superseded (hex-encoded)
	TargetHash string `json:"target_hash"`

	// Type of supersession applied
	SupersessionType string `json:"supersession_type"`

	// Unix timestamp when the supersession was recorded
	Timestamp uint64 `json:"timestamp"`

	// Error message if supersede failed
	Error string `json:"error,omitempty"`
}
