from __future__ import annotations

from pathlib import Path

from youtube_cli_agent.tools.dedupe import DuplicateCheckerTool


def test_dedupe_missing_file(tmp_path: Path) -> None:
    tool = DuplicateCheckerTool(min_transcript_chars=20)
    result = tool.run(tmp_path / "missing.md")
    assert result.exists is False
    assert result.is_valid is False


def test_dedupe_valid_file(tmp_path: Path) -> None:
    content = """# Title

- Channel: Channel
- Video URL: https://www.youtube.com/watch?v=abc
- Publish Date: 2025-01-01
- Duration: 03:00

## Description

desc

## Transcript

This transcript is definitely long enough to pass deterministic integrity checks.

## Metadata

- Transcript Source: Official Caption
- Generated At (UTC): 2025-01-01T00:00:00Z
"""
    path = tmp_path / "valid.md"
    path.write_text(content, encoding="utf-8")

    tool = DuplicateCheckerTool(min_transcript_chars=20)
    result = tool.run(path)

    assert result.exists is True
    assert result.is_valid is True
    assert result.has_transcript is True


def test_dedupe_corrupt_file(tmp_path: Path) -> None:
    path = tmp_path / "corrupt.md"
    path.write_text("# Title\n\nNo required fields", encoding="utf-8")

    tool = DuplicateCheckerTool(min_transcript_chars=20)
    result = tool.run(path)

    assert result.exists is True
    assert result.is_valid is False
    assert result.is_corrupt is True
