"""
Mizan IR (KDL) export — Django management command.

Usage:
    python manage.py export_mizan_ir

Triggers Mizan client discovery to populate the registry, then writes
the canonical Mizan IR as KDL to stdout. The Rust codegen binary
consumes this directly.
"""

from __future__ import annotations

from django.core.management.base import BaseCommand

from mizan_core.ir import build_ir


class Command(BaseCommand):
    help = "Export every registered @client function as Mizan IR (KDL)."

    def handle(self, *args, **options) -> None:
        # Load every project-side @client function so the registry is
        # populated before we emit. Conventionally apps/*/clients.py.
        from mizan.setup.discovery import mizan_clients

        mizan_clients("apps")
        self.stdout.write(build_ir(), ending="")
