from __future__ import annotations

import os
from pathlib import Path


def relpath_under_root(path: Path, root: Path) -> Path:
    try:
        return path.relative_to(root)
    except ValueError:
        rel = os.path.relpath(path, root)
        return Path(*Path(rel).parts)


def website_dest_path(*, out_dir: Path, inbox_dir: Path, src: Path) -> Path:
    rel = relpath_under_root(src, inbox_dir)
    return out_dir / "website" / rel.with_suffix(".webp")


def gbp_dest_paths(*, out_dir: Path, inbox_dir: Path, src: Path) -> tuple[Path, Path]:
    rel = relpath_under_root(src, inbox_dir)
    parent = out_dir / "gbp" / rel.parent
    stem = rel.stem
    return (parent / f"{stem}.jpg", parent / f"{stem}.png")
