from typing import Optional

from backend.pashub_fetcher.core_files import CoreFiles
from backend.pashub_fetcher.evidence_file_data import EvidenceFileData
from backend.pashub_fetcher.pashub_client import PashubClient


def make_client() -> PashubClient:
    return PashubClient(token="test-token")


def make_file(
    file_name: str = "unknown.pdf",
    evidence_category: Optional[str] = None,
    created_utc: str = "2024-01-01T00:00:00",
) -> EvidenceFileData:
    return EvidenceFileData(
        file_id="id-1",
        file_name=file_name,
        created_utc=created_utc,
        file_size=1024,
        file_extension="pdf",
        evidence_category=evidence_category,
    )


# ---------------------------------------------------------------------------
# _get_core_file_type
# ---------------------------------------------------------------------------


def test_get_core_file_type_returns_retrofit_design_doc_for_evidence_category() -> None:
    # Arrange
    client = make_client()
    file = make_file(
        file_name="2512-OSM-H21M900-XX-DR-N-A_Lord Nelson Street 018.pdf",
        evidence_category="retrofit design",
    )

    # Act
    result = client._get_core_file_type(file)

    # Assert
    assert result == CoreFiles.RETROFIT_DESIGN_DOC


def test_get_core_file_type_evidence_category_match_is_case_insensitive() -> None:
    # Arrange
    client = make_client()
    file = make_file(
        file_name="2512-OSM-H21M900-XX-DR-N-A_Lord Nelson Street 018.pdf",
        evidence_category="Retrofit Design",
    )

    # Act
    result = client._get_core_file_type(file)

    # Assert
    assert result == CoreFiles.RETROFIT_DESIGN_DOC
