"""
End-to-end test for Organization onboarding flow.
Uses the authenticated_client fixture to test the POST /api/v1/organizations/onboard endpoint.
"""
import pytest
import httpx


@pytest.mark.asyncio
async def test_organization_onboard(authenticated_client: httpx.AsyncClient):
    """
    Test that a user can create an organization via the onboard endpoint.
    """
    # Prepare payload according to CorpOnboardIn schema
    payload = {
        "full_name": "Test Corporation Kft.",
        "name": "TestCorp",
        "display_name": "Test Corporation",
        "tax_number": "12345678-2-41",
        "reg_number": "01-09-123456",
        "country_code": "HU",
        "language": "hu",
        "default_currency": "HUF",
        # Atomic address fields
        "address_zip": "1234",
        "address_city": "Budapest",
        "address_street_name": "Test",
        "address_street_type": "utca",
        "address_house_number": "1",
        "address_stairwell": "A",
        "address_floor": "2",
        "address_door": "3",
        # Optional contacts
        "contacts": [
            {
                "full_name": "John Doe",
                "email": "john@example.com",
                "phone": "+36123456789",
                "contact_type": "primary"
            }
        ]
    }
    
    response = await authenticated_client.post(
        "/api/v1/organizations/onboard",
        json=payload
    )
    
    # Assert success (201 Created or 200 OK)
    assert response.status_code in (200, 201), f"Unexpected status: {response.status_code}, response: {response.text}"
    
    # Parse response
    data = response.json()
    assert "organization_id" in data
    assert data["organization_id"] > 0
    assert data["status"] == "pending_verification"
    
    print(f"✅ Organization created with ID: {data['organization_id']}")