from django.contrib import admin

from .models import MembershipPlan, Profile, Subscription


@admin.register(MembershipPlan)
class MembershipPlanAdmin(admin.ModelAdmin):
    list_display = ("name", "duration_days", "price", "created_at")
    search_fields = ("name",)
    ordering = ("price",)


@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
    list_display = ("user", "phone", "created_at")
    search_fields = ("user__username", "phone")


@admin.register(Subscription)
class SubscriptionAdmin(admin.ModelAdmin):
    list_display = (
        "user",
        "plan",
        "start_date",
        "end_date",
        "is_active_display",
        "created_at",
    )
    list_filter = ("plan",)
    search_fields = ("user__username", "plan__name")
    readonly_fields = ("created_at",)

    @admin.display(boolean=True, description="Активен")
    def is_active_display(self, obj):
        return obj.is_active
