from datetime import datetime, timezone
from urllib.parse import urlparse
from uuid import uuid4

from app.core.exceptions import AppError
from app.schemas.common import ModuleName


class ConfluenceService:
    async def fetch_page(self, url: str) -> dict:
        parsed = urlparse(url)
        if not parsed.scheme.startswith("http"):
            raise AppError("invalid_url", "Invalid Confluence URL", ModuleName.CONFLUENCE)
        return {
            "page_id": str(uuid4()),
            "title": "Confluence page",
            "content_markdown": f"Fetched content from {url}",
            "version": 1,
            "fetched_at": datetime.now(timezone.utc).isoformat(),
        }
