from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import Employee, GroupCapability, User


@admin.register(User)
class CustomUserAdmin(UserAdmin):
    list_display = (
        'username', 'email', 'role', 'contact', 'is_active',
        'must_change_password', 'locked_until',
    )
    list_filter = ('role', 'is_active', 'must_change_password')
    fieldsets = UserAdmin.fieldsets + (
        (
            'Role & Contact',
            {
                'fields': (
                    'role',
                    'contact',
                    'must_change_password',
                    'failed_login_attempts',
                    'locked_until',
                )
            },
        ),
    )


@admin.register(GroupCapability)
class GroupCapabilityAdmin(admin.ModelAdmin):
    list_display = ('group', 'capability', 'created_at')
    list_filter = ('group',)
    search_fields = ('group__name', 'capability')


@admin.register(Employee)
class EmployeeAdmin(admin.ModelAdmin):
    list_display = ('code', 'first_name', 'last_name', 'role', 'is_active', 'user')
    list_filter = ('role', 'is_active')
    search_fields = ('code', 'first_name', 'last_name', 'email', 'phone', 'user__username')
