from __future__ import annotations

from typing import Literal

from pydantic import BaseModel, Field, confloat, conlist
from pydantic.json_schema import SkipJsonSchema

from noqa_runner.domain.models.actions.base import BaseAction


class SwipeLocation(BaseModel):
    """Vision-detected swipe location with start/end points, confidence and resolution."""

    start_point_2d: conlist(confloat(ge=0, le=1000), min_length=2, max_length=2) = (
        Field(
            description="Swipe start point in normalized coordinates [x, y] in range 0-1000. "
            "x: horizontal axis (0=left, 1000=right). "
            "y: vertical axis (0=top, 1000=bottom)."
        )
    )
    end_point_2d: conlist(confloat(ge=0, le=1000), min_length=2, max_length=2) = Field(
        description="Swipe end point in normalized coordinates [x, y] in range 0-1000. "
        "x: horizontal axis (0=left, 1000=right). "
        "y: vertical axis (0=top, 1000=bottom)."
    )
    confidence: float = Field(
        description="Confidence score from 0.0 to 1.0 indicating how certain the model is about the swipe coordinates",
        ge=0.0,
        le=1.0,
    )
    resolution: SkipJsonSchema[dict[str, int] | None] = Field(
        default=None,
        description="Device screen resolution in pixels {width: int, height: int}",
    )


class VisionSwipe(BaseAction):
    """Swipe on screen using vision-based start and end coordinates"""

    name: Literal["swipe"] = "swipe"
    element_description: str = Field(
        description="Brief description of the swipe gesture and target area"
    )
    location: SkipJsonSchema[SwipeLocation | None] = Field(
        default=None,
        description="Vision-detected swipe location with start/end points, confidence and resolution",
    )

    def get_action_description(self) -> str:
        """Get description of swipe action"""
        return f"Swiped: {self.element_description}"
