from pathlib import Path

from fixtures.generate_fixtures import (
    make_a4_pdf,
    make_a4_pdf_no_metadata,
    make_docx_with_metadata,
    make_image_with_metadata,
    make_image_without_metadata,
)
from mints_prep.detectors.metadata_detector import detect_metadata


def test_pdf_with_metadata_detected(tmp_path: Path):
    p = make_a4_pdf(tmp_path / "with_meta.pdf", with_metadata=True)
    finding = detect_metadata(p)
    assert finding is not None
    assert finding.has_metadata is True
    assert "Author" in finding.detected_fields


def test_pdf_without_metadata_detected(tmp_path: Path):
    p = make_a4_pdf_no_metadata(tmp_path / "no_meta.pdf")
    finding = detect_metadata(p)
    assert finding is not None
    assert finding.has_metadata is False


def test_image_with_exif_detected(tmp_path: Path):
    p = make_image_with_metadata(tmp_path / "photo.jpg")
    finding = detect_metadata(p)
    assert finding is not None
    assert finding.has_metadata is True
    assert "Make" in finding.detected_fields


def test_image_without_exif_detected(tmp_path: Path):
    p = make_image_without_metadata(tmp_path / "plain.png")
    finding = detect_metadata(p)
    assert finding is not None
    assert finding.has_metadata is False


def test_docx_with_metadata_detected(tmp_path: Path):
    p = make_docx_with_metadata(tmp_path / "doc.docx")
    finding = detect_metadata(p)
    assert finding is not None
    assert finding.has_metadata is True
    assert "author" in finding.detected_fields
