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 DragLocation(BaseModel):
    """Vision-detected drag 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="Drag 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="Drag 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 drag 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 VisionDrag(BaseAction):
    """Drag element from one point to another using vision-based coordinates"""

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

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