"""
Export channels schema as OpenAPI JSON for TypeScript generation.

Uses Django Ninja's schema generation for robust Pydantic→OpenAPI conversion.
The schema is consumed by openapi-typescript for type generation.

Usage:
    python manage.py export_channels_schema
"""

import json

from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = "Export channels schema as OpenAPI JSON for TypeScript code generation"

    def add_arguments(self, parser):
        parser.add_argument(
            "--indent",
            type=int,
            default=2,
            help="JSON indentation level (default: 2, use 0 for compact)",
        )

    def handle(self, *args, **options):
        from mizan.channels import get_channels_openapi_schema

        schema = get_channels_openapi_schema()

        indent = options["indent"] if options["indent"] > 0 else None
        output = json.dumps(schema, indent=indent)

        self.stdout.write(output)
