from django.contrib import admin

from .models import Order, OrderItem, Product, Table, UserRole


class OrderItemInline(admin.TabularInline):
    model = OrderItem
    extra = 0


@admin.register(UserRole)
class UserRoleAdmin(admin.ModelAdmin):
    list_display = ("user", "role", "updated_at")
    list_filter = ("role",)
    search_fields = ("user__username", "user__email", "user__first_name", "user__last_name")


@admin.register(Table)
class TableAdmin(admin.ModelAdmin):
    list_display = ("name", "status", "seats", "area", "updated_at")
    list_filter = ("status", "area")
    search_fields = ("name",)


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ("name", "category", "price", "station", "is_available")
    list_filter = ("category", "station", "is_available")
    search_fields = ("name",)


@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ("id", "table", "status", "created_at", "paid_at")
    list_filter = ("status", "created_at")
    search_fields = ("table__name", "guest_name")
    inlines = [OrderItemInline]
