"""
Tests for pipeline result classes.
"""

import pytest

from pycharter.etl_generator.result import BatchResult, LoadResult, PipelineResult


class TestLoadResult:
    """Tests for LoadResult."""

    def test_basic_result(self):
        """Test basic result creation."""
        result = LoadResult(success=True, rows_loaded=100)

        assert result.success is True
        assert result.rows_loaded == 100

    def test_failure_result(self):
        """Test failure result."""
        result = LoadResult(success=False, error="Connection failed")

        assert result.success is False
        assert result.error == "Connection failed"


class TestBatchResult:
    """Tests for BatchResult."""

    def test_success_property(self):
        """Test success property."""
        result = BatchResult(batch_index=0, rows_in=100, rows_out=100)

        assert result.success is True

    def test_failure_with_errors(self):
        """Test failure with errors."""
        result = BatchResult(batch_index=0, rows_in=100, errors=["Error"])

        assert result.success is False

    def test_failure_with_failed_rows(self):
        """Test failure with failed rows."""
        result = BatchResult(batch_index=0, rows_in=100, rows_failed=10)

        assert result.success is False


class TestPipelineResult:
    """Tests for PipelineResult."""

    def test_basic_result(self):
        """Test basic result creation."""
        result = PipelineResult(
            success=True,
            rows_extracted=1000,
            rows_transformed=1000,
            rows_loaded=1000,
        )

        assert result.success is True
        assert result.rows_extracted == 1000
        assert result.rows_transformed == 1000
        assert result.rows_loaded == 1000

    def test_to_dict(self):
        """Test to_dict method."""
        result = PipelineResult(
            success=True,
            rows_extracted=100,
            rows_loaded=100,
            pipeline_name="test",
        )

        d = result.to_dict()

        assert d["success"] is True
        assert d["rows_extracted"] == 100
        assert d["pipeline_name"] == "test"

    def test_with_errors(self):
        """Test result with errors."""
        result = PipelineResult(
            success=False,
            errors=["Connection failed", "Timeout"],
        )

        assert result.success is False
        assert len(result.errors) == 2
