from __future__ import annotations

from pathlib import Path
from typing import Any

from .preview3d import LIVE_AO_TEXTURE_NAME, safe_segment


def car_ao_library_path(converted_textures_root: Path, car_model: Any) -> Path:
    car_id = safe_segment(car_model, "car")
    return Path(converted_textures_root) / car_id / LIVE_AO_TEXTURE_NAME


def car_ao_game_texture_path(game_root: Path, car_model: Any) -> Path:
    car_id = safe_segment(car_model, "car")
    return Path(game_root) / "content" / "cars" / car_id / "textures" / LIVE_AO_TEXTURE_NAME.replace(".png", ".texture")


def car_ao_texture_status(converted_textures_root: Path, game_root: Path, car_model: Any) -> dict[str, Any]:
    source = car_ao_game_texture_path(game_root, car_model)
    target = car_ao_library_path(converted_textures_root, car_model)
    return {
        "carModel": safe_segment(car_model, "car"),
        "sourceTexturePath": str(source),
        "sourceTextureExists": source.exists(),
        "sourceTexturemipsPath": str(source.with_suffix(".texturemips")),
        "sourceTexturemipsExists": source.with_suffix(".texturemips").exists(),
        "targetPngPath": str(target),
        "targetPngExists": target.exists(),
    }
