"""
Tests for services/quality/pipeline.py
"""
import pytest

from services.quality import run_l0_check
from services.quality.script_detector import DocumentQualityResult


class TestRunL0Check:
    def test_returns_result_on_success(self):
        result = run_l0_check(
            ["Hello", "World"],
            ["Bonjour", "Monde"],
            "fr",
            job_id="test_job_1",
        )
        assert isinstance(result, DocumentQualityResult)
        assert result.passed is True
        assert result.chunk_count == 2

    def test_returns_neutral_on_empty_lists(self):
        result = run_l0_check([], [], "fr", job_id="test_job_2")
        assert result.passed is True
        assert result.chunk_count == 0

    def test_detects_failures(self):
        result = run_l0_check(
            ["Hello", "World"],
            ["Bonjour", "مرحبا"],
            "fr",
            job_id="test_job_3",
        )
        assert result.passed is False
        assert "wrong_script" in result.issues

    def test_never_raises_on_bad_input(self):
        # Even with weird input, it shouldn't raise
        result = run_l0_check(
            ["Hello"],
            [None],  # None translation
            "fr",
            job_id="test_job_4",
        )
        assert result is not None

    def test_optional_job_id(self):
        # job_id is optional
        result = run_l0_check(["hi"], ["salut"], "fr")
        assert result is not None

    def test_optional_file_extension(self):
        result = run_l0_check(
            ["hi"], ["salut"], "fr", file_extension=".docx"
        )
        assert result is not None

    def test_target_lang_none(self):
        # Should not crash with no target lang
        result = run_l0_check(["hi"], ["salut"], None)
        assert result is not None
