"""Register bundled system fonts (Inter, OFL) in the DB and storage."""

from typing import Any

from django.core.management.base import BaseCommand

from snapfile.assets.fonts import ensure_system_fonts, reprepare_fonts


class Command(BaseCommand):
    help = "Prepare bundled fonts (pdf.ttf, metrics.json, web.woff2) and register them as system fonts"

    def add_arguments(self, parser: Any) -> None:
        parser.add_argument("--reprepare", action="store_true", help="Rebuild prepared files of all existing fonts")

    def handle(self, *args: Any, **opts: Any) -> None:
        if opts["reprepare"]:
            self.stdout.write(f"re-prepared fonts: {reprepare_fonts()}")
        for f in ensure_system_fonts():
            self.stdout.write(f"{f.family} {f.weight} {f.style}")
