"""Unit tests for InvoicePDFService."""

from pathlib import Path

import pytest

from app.modules.orders.services.invoice_pdf_service import (
    TEMPLATE_DIR,
    InvoicePDFService,
)


@pytest.mark.unit
@pytest.mark.orders
class TestInvoicePDFService:
    """Test suite for InvoicePDFService."""

    def setup_method(self):
        self.service = InvoicePDFService()

    def test_service_instantiation(self):
        """Service can be instantiated."""
        assert self.service is not None

    def test_template_directory_exists(self):
        """Template directory must exist at the expected path."""
        assert TEMPLATE_DIR.exists(), f"Template directory missing: {TEMPLATE_DIR}"
        assert TEMPLATE_DIR.is_dir()

    def test_invoice_template_exists(self):
        """invoice.html template must exist in the template directory."""
        template_path = TEMPLATE_DIR / "invoice.html"
        assert template_path.exists(), f"Invoice template missing: {template_path}"

    def test_template_can_be_loaded(self):
        """Jinja2 environment can load the invoice template."""
        template = self.service.env.get_template("invoice.html")
        assert template is not None

    def test_template_dir_is_inside_orders_module(self):
        """Template directory should be inside the orders module, not the global templates."""
        orders_module_dir = Path(__file__).parent.parent.parent
        assert str(TEMPLATE_DIR).startswith(str(orders_module_dir)), (
            f"TEMPLATE_DIR ({TEMPLATE_DIR}) should be inside orders module ({orders_module_dir})"
        )
