"""
Outcome Domain Receipts

Receipt types for execution outcome tracking and learning.

All outcome receipts are Ed25519-signed, JCS-canonical, and linked to the
execution events they record.

---
feature:
  id: feature.outcome_receipts
  name: Outcome Domain Receipts
  kind: module
  summary: Receipt models for execution outcomes and learning queries
  owners: ["@agent-c"]
  stage: experimental
  tags: [receipts, outcomes, learning, organism]
  depends_on: [feature.receipt_writer, feature.outcome_indexer]
  inputs: [Execution outcomes, learning bridge queries]
  outputs: [Signed outcome receipts in ledger]
  invariants:
    - All outcome receipts are Ed25519-signed
    - Each outcome is linked to the task it executed
    - Learning queries are auditable via receipts
---
"""

from __future__ import annotations

import logging
from typing import Any, Dict, Optional

from pydantic import Field

from receipts.base import BaseReceipt

logger = logging.getLogger(__name__)


class OutcomeRecordedReceipt(BaseReceipt):
    """
    Emitted when an execution outcome is recorded.

    Provides audit trail for what happened after execution.
    """

    receipt_type: str = Field(default="OutcomeRecordedReceipt", alias="type")
    domain: str = Field(default="organism")

    # Outcome identity
    outcome_id: str = Field(description="Unique ID for this outcome")
    task_type: str = Field(description="Type of task that executed")
    task_id: str = Field(description="ID of the task")

    # Result
    status: str = Field(description="Outcome status: success, failure, partial, timeout, blocked")
    duration_ms: float = Field(description="How long execution took in milliseconds")

    # Context
    model_used: Optional[str] = Field(default=None, description="Which LLM model was used")


class LearningQueryReceipt(BaseReceipt):
    """
    Emitted when learning bridge is queried.

    Provides audit trail for learning system queries (e.g., from prophecy).
    """

    receipt_type: str = Field(default="LearningQueryReceipt", alias="type")
    domain: str = Field(default="organism")

    # Query identity
    query_type: str = Field(description="Type of query: historical_performance, similar_outcomes, etc.")
    task_type: str = Field(description="Task type being queried")

    # Result summary
    result_summary: Dict[str, Any] = Field(description="Summary of query results")
