from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import CustomUser


@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
    """Admin interface for CustomUser."""
    
    # Add custom fields to the user admin
    fieldsets = UserAdmin.fieldsets + (
        ('CAS Information', {
            'fields': ('cas_user_id', 'cas_groups', 'cas_attributes'),
        }),
    )
    
    # Add custom fields to the list display
    list_display = UserAdmin.list_display + ('cas_user_id', 'get_cas_groups_display')
    
    # Add search fields
    search_fields = UserAdmin.search_fields + ('cas_user_id',)
    
    # Add filters
    list_filter = UserAdmin.list_filter + ('cas_groups',)
    
    # Make CAS fields readonly in admin
    readonly_fields = ('cas_user_id', 'cas_groups', 'cas_attributes')
    
    def get_cas_groups_display(self, obj):
        """Display CAS groups in admin list."""
        return obj.get_cas_groups_display()
    get_cas_groups_display.short_description = 'CAS Groups'