from django.contrib import admin
from django.http import HttpResponseRedirect
from .models import Profile, Racer, Product, Invoice, InvoiceProduct


@admin.register(Racer)
class RacerAdmin(admin.ModelAdmin):
    list_display = ("first_name", "last_name", "email", "team", "phone", "date_of_birth")


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ("name", "description", "price", "quantity")


@admin.register(Invoice)
class InvoiceAdmin(admin.ModelAdmin):
    list_display = ("invoice_id", "user", "total_price", "paid", "address")
    change_form_template = "invoice_custom_admin_page.html"

    def response_change(self, request, obj):
        if "_invoice" in request.POST:
            return HttpResponseRedirect(f"/api/invoice?invoice_id={obj.invoice_id}")
        return super(self).response_change(request, obj)


@admin.register(InvoiceProduct)
class InvoiceProductAdmin(admin.ModelAdmin):
    pass


@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
    pass
