"""Tests for billing service."""
import pytest
from app.domains.billing.service import create_invoice, get_invoices


@pytest.mark.asyncio
async def test_create_invoice_minimal(db, admin_user):
    """Invoice kann mit Mindestdaten erstellt werden."""
    invoice = await create_invoice(
        db,
        tenant_id=None,
        order_line_ids=[],
        notes="Test invoice",
    )
    assert invoice.id is not None
    assert invoice.invoice_number.startswith("INV-")
    assert invoice.status == "draft"
    assert invoice.currency == "EUR"


@pytest.mark.asyncio
async def test_invoice_number_sequential(db, admin_user):
    """Invoice-Nummern sind sequenziell und eindeutig."""
    inv1 = await create_invoice(db, tenant_id=None, order_line_ids=[], notes="First")
    inv2 = await create_invoice(db, tenant_id=None, order_line_ids=[], notes="Second")
    assert inv1.invoice_number != inv2.invoice_number


@pytest.mark.asyncio
async def test_get_invoices_returns_list(db):
    """get_invoices gibt eine Liste zurück."""
    invoices = await get_invoices(db, tenant_id=None)
    assert isinstance(invoices, list)
