from django.contrib import admin

from apps.sales.models import Customer, ProjectSale, PropertyPayment, PropertyUnit


@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
    list_display = ("name", "email", "phone", "country")
    search_fields = ("name", "email")


@admin.register(PropertyUnit)
class PropertyUnitAdmin(admin.ModelAdmin):
    list_display = ("unit_code", "project", "status", "list_price")
    list_filter = ("status", "project")
    search_fields = ("unit_code",)


class PaymentInline(admin.TabularInline):
    model = PropertyPayment
    extra = 0


@admin.register(ProjectSale)
class ProjectSaleAdmin(admin.ModelAdmin):
    list_display = ("unit", "customer", "stage", "contracted_amount", "collected_amount")
    list_filter = ("stage", "project")
    inlines = [PaymentInline]
