"""
Abstract base classes (ports) for provider interfaces.

These ABCs define the contracts that all provider implementations must follow.
Each provider type (image, video, TTS) has a single async interface.
"""

from __future__ import annotations

from abc import ABC, abstractmethod
from collections.abc import Callable
from pathlib import Path
from typing import Any


class ImageProvider(ABC):
    """Port: text prompt → image file."""

    name: str  # Provider identifier (e.g. "google_flow", "dalle3", "pollinations")

    @abstractmethod
    async def generate(self, prompt: str, output_path: Path, **kwargs: Any) -> Path:
        """Generate an image from prompt, save to output_path, return path."""
        ...

    async def close(self) -> None:
        """Cleanup resources. Override for providers with browsers/connections."""
        pass


class VideoProvider(ABC):
    """Port: image + prompt → video file."""

    name: str

    @abstractmethod
    async def generate(
        self,
        image_path: Path,
        video_prompt: str,
        output_path: Path,
        on_progress: Callable[[int], None] | None = None,
    ) -> Path:
        """Generate video from image+prompt, save to output_path, return path."""
        ...

    async def close(self) -> None:
        """Cleanup resources. Override for providers with browsers/connections."""
        pass


class TTSProvider(ABC):
    """Port: text → audio file."""

    name: str

    @abstractmethod
    async def generate(self, text: str, output_path: Path) -> Path:
        """Generate speech audio, save to output_path, return path."""
        ...

    @staticmethod
    @abstractmethod
    def get_audio_duration(audio_path: Path) -> float:
        """Return audio duration in seconds."""
        ...

    async def close(self) -> None:
        """Cleanup resources. Override for providers with browsers/connections."""
        pass
