from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User,ServiceRequest,Service  # Import your custom User model

class CustomUserAdmin(UserAdmin):
    model = User

    # Fields to display in the list view of the admin
    list_display = ['email', 'first_name', 'last_name', 'is_staff', 'is_superuser', 'is_active']

    # Fields to search in the admin
    search_fields = ['email', 'first_name', 'last_name']

    # Default ordering of records in the admin
    ordering = ['email']

    # Fieldsets for the add and change forms in the admin
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        ('Personal Info', {'fields': ('first_name', 'last_name','profile','service_offered')}),
        ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser')}),
        ('Important Dates', {'fields': ('last_login',)}),  # Remove 'date_joined' if it doesn't exist
    )

    # Fieldsets for the add form in the admin
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'first_name', 'last_name','profile','service_offered', 'password1', 'password2', 'is_staff', 'is_superuser', 'is_active'),
        }),
    )

    # Filters for the list view in the admin
    list_filter = ('is_staff', 'is_superuser', 'is_active')

# Register your custom User model with the custom UserAdmin class
admin.site.register(User, CustomUserAdmin)
admin.site.register(ServiceRequest)
admin.site.register(Service)