from django.core.management.base import BaseCommand
from users.models import Subscription, UserAccount

class Command(BaseCommand):
    help = 'Check subscription credits for a user by email'

    def add_arguments(self, parser):
        parser.add_argument('email', type=str, help='User email')

    def handle(self, *args, **options):
        email = options['email']
        try:
            user = UserAccount.objects.get(email=email)
        except UserAccount.DoesNotExist:
            self.stdout.write(self.style.ERROR(f'User with email {email} does not exist.'))
            return
        subs = Subscription.objects.filter(user=user).order_by('-expiry_date')
        if not subs.exists():
            self.stdout.write(self.style.WARNING(f'No subscriptions found for {email}'))
            return
        sub = subs.first()
        self.stdout.write(self.style.SUCCESS(f'Subscription for {email}:'))
        self.stdout.write(f'  hide_address_count: {sub.hide_address_count}')
        self.stdout.write(f'  hide_contact_count: {sub.hide_contact_count}')
        self.stdout.write(f'  expiry_date: {sub.expiry_date}') 