"""
Workflow Test: General Turnero Flow

This is a COMPOSITION test that validates the full turnero flow
by calling endpoints in sequence. Use this to ensure the flow works
end-to-end, but individual endpoint behavior is tested in app folders.

Flow:
1. Check coverage at address
2. Create pet owner (guest with mock email)
3. Create pet for owner
4. Get available services for pet
5. Create service request

Frontend route: /turnos/
User type: Guest (invitado)
"""

from ..base import ContractTestCase
from ..endpoints import Endpoints
from ..helpers import sample_pet_owner, unique_email, SAMPLE_CAT


class TestTurneroGeneralFlow(ContractTestCase):
    """
    End-to-end flow test for general turnero.

    Note: This tests the SEQUENCE of calls, not individual endpoint behavior.
    Individual endpoint tests are in mascotas/, productos/, solicitudes/.
    """

    def test_full_flow_sequence(self):
        """
        Complete turnero flow should work end-to-end.

        This test validates that a guest user can complete the full
        appointment booking flow.
        """
        # Step 0: Check coverage at address
        coverage_response = self.get(Endpoints.COVERAGE_CHECK, params={
            "lat": -34.6037,
            "lng": -58.3816,
        })
        self.assert_status(coverage_response, 200)

        # Step 1: Create pet owner (frontend creates mock email for guest)
        mock_email = unique_email("invitado")
        owner_data = sample_pet_owner(mock_email)
        owner_response = self.post(Endpoints.PET_OWNERS, owner_data)
        self.assert_status(owner_response, 201)
        owner_id = owner_response.data["id"]

        # Step 2: Create pet for owner
        pet_data = {**SAMPLE_CAT, "owner": owner_id}
        pet_response = self.post(Endpoints.PETS, pet_data)
        self.assert_status(pet_response, 201)
        pet_id = pet_response.data["id"]

        # Step 3: Get services (optionally filtered by pet)
        services_response = self.get(Endpoints.SERVICES, params={"pet_id": pet_id})
        # Services endpoint may return 200 even without pet filter
        self.assertIn(services_response.status_code, [200, 404])

        # Note: Steps 4-5 (select date/time, create service request) require
        # more setup (available times, cart, etc.) and are tested separately.
