from django.contrib import admin
from .models import LeadershipAssignment, LeadershipPosition

@admin.register(LeadershipPosition)
class LeadershipPositionAdmin(admin.ModelAdmin):
    list_display = ("name", "level", "rank", "active")
    list_filter = ("level", "active")
    search_fields = ("name",)
    list_editable = ("rank", "active")

@admin.register(LeadershipAssignment)
class LeadershipAssignmentAdmin(admin.ModelAdmin):
    list_display = ("member", "position", "campus", "starts_on", "ends_on", "active")
    list_filter = ("active", "position__level", "position", "campus")
    search_fields = ("user__first_name", "user__last_name", "user__phone_number", "position__name")
    autocomplete_fields = ("user",)
    list_select_related = ("user", "position", "campus")

    @admin.display(description="Member", ordering="user__first_name")
    def member(self, obj): return obj.user.get_full_name() or obj.user.phone_number
