from typing import List

from fastapi import APIRouter
from fastapi_camelcase import CamelModel
from pydantic import confloat

from .. import scoring
from ..schemas import CacheInfo, GeneratorInfo
from ..point_gen import points, generator_info

router = APIRouter()


class Point(CamelModel):
    lat: confloat(ge=-90.0, le=90.0)
    lng: confloat(ge=-180.0, le=180.0)


class ScoreCheck(CamelModel):
    point1: Point
    point2: Point


class Score(CamelModel):
    distance: float
    score: int


class CacheResponse(CamelModel):
    caches: List[CacheInfo]


class GeneratorResponse(CamelModel):
    generators: List[GeneratorInfo]


@router.get("/health")
def health():
    return { "status": "healthy", "version": "3.0" }


@router.post("/score", response_model=Score)
def check_score(points: ScoreCheck):
    score, distance = scoring.score((points.point1.lat, points.point1.lng), (points.point2.lat, points.point2.lng))
    return Score(distance=distance, score=score)


@router.get("/caches", response_model=CacheResponse)
def caches():
    return CacheResponse(caches=points.get_cache_info())


@router.get("/generators", response_model=GeneratorResponse)
def generators():
    return GeneratorResponse(generators=generator_info)
