"""Shared integration data models."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any


@dataclass(slots=True)
class UnifiedTask:
    """Cross-provider normalized task shape."""

    provider: str
    id: str
    title: str
    description: str | None = None
    due_date: str | None = None
    due_string: str | None = None
    priority: int | None = None
    completed: bool = False
    overdue: bool = False
    raw: dict[str, Any] = field(default_factory=dict)

    @property
    def content(self) -> str:
        """Backward-compatible alias for legacy task title key."""
        return self.title

    def to_api_dict(self) -> dict[str, Any]:
        """Return backward-compatible task API payload."""
        due_payload: dict[str, Any] | None = None
        if self.due_date or self.due_string:
            due_payload = {
                "date": self.due_date,
                "string": self.due_string,
            }
        return {
            "provider": self.provider,
            "id": self.id,
            "title": self.title,
            "content": self.title,
            "description": self.description,
            "due": due_payload,
            "due_date": self.due_date,
            "due_string": self.due_string,
            "priority": self.priority,
            "completed": bool(self.completed),
            "overdue": bool(self.overdue),
            **(self.raw or {}),
        }


@dataclass(slots=True)
class NotesHit:
    """Cross-provider normalized notes search hit."""

    provider: str
    id: str
    title: str
    snippet: str
    source: str
    raw: dict[str, Any] = field(default_factory=dict)

    def to_dict(self) -> dict[str, Any]:
        """Return API-ready payload."""
        return {
            "provider": self.provider,
            "id": self.id,
            "title": self.title,
            "snippet": self.snippet,
            "source": self.source,
            "raw": self.raw,
        }


@dataclass(slots=True)
class ProviderConnectionResult:
    """Minimal provider test-connection result."""

    ok: bool
    detail: str
