from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password

User = get_user_model()


class Command(BaseCommand):
    help = 'Create a test user named "phin"'

    def handle(self, *args, **options):
        self.stdout.write('Creating test user "phin"...')
        
        # Check if user already exists
        if User.objects.filter(username='phin').exists():
            self.stdout.write(
                self.style.WARNING('User "phin" already exists. Skipping creation.')
            )
            return
        
        # Create test user
        test_user = User.objects.create(
            username='phin',
            email='phin@test.com',
            first_name='Phin',
            last_name='Test',
            password=make_password('test123'),  # Set password
            role='borrower',  # Make them a client/borrower
            is_staff=False,  # Not staff since they're a client
            is_active=True,
            phone_number='+254700000000',
            status='active'
        )
        
        self.stdout.write(
            self.style.SUCCESS(
                f'Successfully created test user:\n'
                f'Username: phin\n'
                f'Password: test123\n'
                f'Email: phin@test.com\n'
                f'Role: Client/Borrower\n'
                f'Status: Active'
            )
        ) 