from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SOURCE = (ROOT / "app" / "jasmin_service.py").read_text(encoding="utf-8")


def test_customer_not_found_is_treated_as_autocreate_case():
    assert "def _is_jasmin_customer_not_found" in SOURCE
    assert "does not correspond to an existing customer" in SOURCE.lower()
    assert "except JasminError as exc" in SOURCE
    assert "result = None" in SOURCE
    assert "if not _is_jasmin_customer_not_found(exc):" in SOURCE


def test_jasmin_customer_creation_requires_minimum_fiscal_address_data():
    assert "missing_address = []" in SOURCE
    assert "morada fiscal" in SOURCE
    assert "código postal" in SOURCE
    assert "cidade" in SOURCE
    assert "Cliente não existe no Jasmin e faltam dados para criar Customer" in SOURCE


def test_confirmation_after_customer_create_is_non_blocking():
    assert "confirm_warning" in SOURCE
    assert "indexação por NIF" in SOURCE
    assert '"confirm_warning": confirm_warning' in SOURCE
