from pathlib import Path

from fixtures.generate_fixtures import (
    make_a4_pdf,
    make_extension_mismatch_file,
    make_unsupported_file,
)
from mints_prep.detectors.format_detector import detect_format
from mints_prep.models import FormatStatus


def test_valid_pdf_is_record_ready(tmp_path: Path):
    p = make_a4_pdf(tmp_path / "test.pdf")
    status, detected = detect_format(p)
    assert status == FormatStatus.RECORD_READY
    assert detected == "PDF"


def test_docx_is_convertible(tmp_path: Path):
    p = tmp_path / "test.docx"
    from fixtures.generate_fixtures import make_docx_with_metadata

    make_docx_with_metadata(p)
    status, detected = detect_format(p)
    assert status == FormatStatus.CONVERTIBLE
    assert detected == "DOCX"


def test_unsupported_extension(tmp_path: Path):
    p = make_unsupported_file(tmp_path / "test.zip")
    status, _ = detect_format(p)
    assert status == FormatStatus.UNSUPPORTED


def test_extension_mismatch(tmp_path: Path):
    p = make_extension_mismatch_file(tmp_path / "fake.pdf")
    status, _ = detect_format(p)
    assert status == FormatStatus.EXTENSION_MISMATCH
