"""
Management command to display the current INTERNAL_API_KEY
Useful for copying to nginx configuration
"""
from django.core.management.base import BaseCommand
from django.conf import settings


class Command(BaseCommand):
    help = 'Display the current INTERNAL_API_KEY for nginx configuration'

    def handle(self, *args, **options):
        api_key = getattr(settings, 'INTERNAL_API_KEY', None)
        
        if not api_key:
            self.stdout.write(
                self.style.ERROR('❌ INTERNAL_API_KEY is not set!')
            )
            self.stdout.write(
                '   Set it in your .env file or it will be auto-generated in DEBUG mode.'
            )
            return
        
        self.stdout.write(self.style.SUCCESS('\n✓ Current INTERNAL_API_KEY:'))
        self.stdout.write(self.style.WARNING(f'\n{api_key}\n'))
        
        self.stdout.write('📋 Copy this key to your nginx configuration:')
        self.stdout.write('   In nginx.conf, set:')
        self.stdout.write(f'   set $api_key "{api_key}";')
        self.stdout.write('')
        self.stdout.write('   Or add to your .env file:')
        self.stdout.write(f'   INTERNAL_API_KEY={api_key}')
        self.stdout.write('')

