"""
Management command to reset is_new_employee flag for all users.
This can be used to fix any users who are stuck in the password change loop.
"""

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User


class Command(BaseCommand):
    help = 'Reset is_new_employee flag to False for all users'

    def add_arguments(self, parser):
        parser.add_argument(
            '--confirm',
            action='store_true',
            help='Confirm the action to proceed with the reset',
        )

    def handle(self, *args, **options):
        if not options['confirm']:
            self.stdout.write(
                self.style.WARNING(
                    'This command will set is_new_employee=False for all users.\n'
                    'Use --confirm to proceed.'
                )
            )
            return

        # Update all users to have is_new_employee=False
        users_updated = User.objects.filter(is_new_employee=True).update(is_new_employee=False)
        
        self.stdout.write(
            self.style.SUCCESS(
                f'Successfully updated {users_updated} users. '
                f'All users now have is_new_employee=False'
            )
        )