"""Integration tests for all services.

These tests require a valid API key set in the SEDSH_API_KEY environment variable.
They make real API calls and test the full SDK functionality.

Run with: pytest tests/test_services_integration.py -v -m integration
"""

import os
import pytest
from sed_sh import SedSH


@pytest.mark.integration
class TestLinksServiceIntegration:
    """Integration tests for Links service."""

    def test_create_and_delete_link(self):
        """Test creating and deleting a link with real API."""
        api_key = os.getenv("SEDSH_API_KEY")
        if not api_key:
            pytest.skip("SEDSH_API_KEY not set")

        client = SedSH(api_key=api_key)

        # Create link
        result = client.links.create("https://github.com/anthropics/claude-code")
        assert "code" in result
        assert "shortUrl" in result
        code = result["code"]

        # List links (should include our new link)
        links = client.links.list()
        assert "links" in links

        # Delete link
        delete_result = client.links.delete(code)
        assert delete_result["success"] is True


@pytest.mark.integration
class TestInboxServiceIntegration:
    """Integration tests for Inbox service."""

    def test_create_and_delete_inbox(self):
        """Test creating and deleting an inbox with real API."""
        api_key = os.getenv("SEDSH_API_KEY")
        if not api_key:
            pytest.skip("SEDSH_API_KEY not set")

        client = SedSH(api_key=api_key)

        # Create inbox
        result = client.inbox.create()
        assert "code" in result
        assert "email" in result
        code = result["code"]

        # List inboxes
        inboxes = client.inbox.list()
        assert "inboxes" in inboxes

        # Get messages (should be empty)
        messages = client.inbox.get_messages(code)
        assert "messages" in messages

        # Delete inbox
        delete_result = client.inbox.delete(code)
        assert delete_result["success"] is True
