from fastapi import APIRouter, Depends

from models.api import (
    FlightCreateRequest,
    FlightResponse,
    FlightDetailResponse,
    FlightStatusResponse,
    DeleteResponse,
    UpdateResponse,
    UserFixRequest,
    UserFixResponse,
    ObjectGPSResponse,
)
from models.core import GPSPoint
from api.dependencies import get_flight_api
from components.flight_api import FlightAPIBase

router = APIRouter()


@router.post("", response_model=FlightResponse)
async def create_flight(
    request: FlightCreateRequest,
    api: FlightAPIBase = Depends(get_flight_api),
) -> FlightResponse:
    return await api.create_flight(request)


@router.get("/{flight_id}", response_model=FlightDetailResponse)
async def get_flight(
    flight_id: str,
    api: FlightAPIBase = Depends(get_flight_api),
) -> FlightDetailResponse:
    return await api.get_flight(flight_id)


@router.get("/{flight_id}/status", response_model=FlightStatusResponse)
async def get_flight_status(
    flight_id: str,
    api: FlightAPIBase = Depends(get_flight_api),
) -> FlightStatusResponse:
    return await api.get_flight_status(flight_id)


@router.delete("/{flight_id}", response_model=DeleteResponse)
async def delete_flight(
    flight_id: str,
    api: FlightAPIBase = Depends(get_flight_api),
) -> DeleteResponse:
    return await api.delete_flight(flight_id)


@router.put("/{flight_id}/waypoints", response_model=UpdateResponse)
async def update_waypoints(
    flight_id: str,
    waypoints: list[GPSPoint],
    api: FlightAPIBase = Depends(get_flight_api),
) -> UpdateResponse:
    return await api.update_waypoints(flight_id, waypoints)


@router.post("/{flight_id}/user-fix", response_model=UserFixResponse)
async def submit_user_fix(
    flight_id: str,
    request: UserFixRequest,
    api: FlightAPIBase = Depends(get_flight_api),
) -> UserFixResponse:
    return await api.submit_user_fix(flight_id, request)


@router.get("/{flight_id}/frames/{frame_id}/object-gps", response_model=ObjectGPSResponse)
async def get_object_gps(
    flight_id: str,
    frame_id: int,
    pixel_x: float,
    pixel_y: float,
    api: FlightAPIBase = Depends(get_flight_api),
) -> ObjectGPSResponse:
    return await api.get_object_gps(flight_id, frame_id, (pixel_x, pixel_y))

