"""Result types for pipeline execution."""
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Optional

from nirs4all.data.dataset import SpectroDataset
from nirs4all.data.predictions import Predictions
from nirs4all.pipeline.config.context import ExecutionContext


@dataclass
class ArtifactMeta:
    """Metadata about a persisted artifact.

    Attributes:
        name: Artifact identifier (e.g., 'model', 'scaler')
        content_hash: Content-based hash for deduplication
        path: Relative path from artifacts directory
        format: Artifact format (e.g., 'joblib', 'h5', 'safetensors')
        format_version: Version of the library used (e.g., 'sklearn==1.3.0')
        nirs4all_version: Version of nirs4all used (e.g., '0.4.1')
        metadata: Additional artifact metadata
    """
    name: str
    content_hash: str
    path: str
    format: str
    format_version: str = ""
    nirs4all_version: str = ""
    metadata: dict[str, Any] = field(default_factory=dict)

@dataclass
class StepOutput:
    """Standardized output from a controller execution.

    Attributes:
        artifacts: Internal binaries (models, transformers) to be persisted for reproducibility.
                  List of tuples: (object, name, format_hint).
        outputs: User outputs (charts, reports) to be saved as files.
                List of tuples: (data_object, filename_hint, type_hint).
        metadata: Metadata to be added to the context or logs.
    """
    artifacts: list[tuple[Any, str, str | None]] = field(default_factory=list)
    outputs: list[tuple[Any, str, str]] = field(default_factory=list)
    metadata: dict[str, Any] = field(default_factory=dict)

@dataclass
class StepResult:
    """Result of executing a single pipeline step.

    Attributes:
        updated_context: Updated execution context after step
        artifacts: List of artifacts persisted during step execution
        outputs: List of output files saved during step execution
        predictions: Optional predictions generated by this step
    """
    updated_context: ExecutionContext
    artifacts: list[Any] = field(default_factory=list)
    outputs: list[Any] = field(default_factory=list)
    predictions: Predictions | None = None

