from __future__ import annotations

from typing import Literal


ModelScale = Literal["small", "professional", "large", "extreme"]
ResultDetailRequest = Literal["auto", "full", "compact"]
ResolvedResultDetail = Literal["full", "compact"]

SMALL_MODEL_MAX_ELEMENTS = 5_000
PROFESSIONAL_MODEL_MAX_ELEMENTS = 30_000
LARGE_MODEL_MAX_ELEMENTS = 100_000
AUTO_COMPACT_ELEMENT_THRESHOLD = 8_000
COMPACT_MAX_DIAGRAM_POINTS = 5


def classify_model_scale(element_count: int) -> ModelScale:
    if element_count <= SMALL_MODEL_MAX_ELEMENTS:
        return "small"
    if element_count <= PROFESSIONAL_MODEL_MAX_ELEMENTS:
        return "professional"
    if element_count <= LARGE_MODEL_MAX_ELEMENTS:
        return "large"
    return "extreme"


def resolve_result_detail(
    requested: ResultDetailRequest,
    element_count: int,
) -> ResolvedResultDetail:
    if requested == "auto":
        return "compact" if element_count > AUTO_COMPACT_ELEMENT_THRESHOLD else "full"
    return requested


def returned_diagram_points(requested_points: int, detail: ResolvedResultDetail) -> int:
    if detail == "compact":
        return min(requested_points, COMPACT_MAX_DIAGRAM_POINTS)
    return requested_points
