from django.contrib import admin

from .models import ActivityItem, QuoteLine, SalesWorkspace


class QuoteLineInline(admin.TabularInline):
    model = QuoteLine
    extra = 0


class ActivityItemInline(admin.TabularInline):
    model = ActivityItem
    extra = 0


@admin.register(SalesWorkspace)
class SalesWorkspaceAdmin(admin.ModelAdmin):
    list_display = (
        "customer_name",
        "project_number",
        "opportunity_title",
        "stage",
        "estimated_value",
        "updated_at",
    )
    list_filter = ("stage", "layout_template")
    search_fields = (
        "customer_name",
        "project_name",
        "project_number",
        "zipcode",
        "address",
        "opportunity_title",
    )
    inlines = [QuoteLineInline, ActivityItemInline]


@admin.register(QuoteLine)
class QuoteLineAdmin(admin.ModelAdmin):
    list_display = ("product_name", "workspace", "quantity", "unit_price", "created_at")
    search_fields = ("product_name", "workspace__customer_name", "workspace__project_number")


@admin.register(ActivityItem)
class ActivityItemAdmin(admin.ModelAdmin):
    list_display = ("title", "workspace", "activity_type", "due_at", "owner", "is_done")
    list_filter = ("activity_type", "is_done")
    search_fields = ("title", "workspace__customer_name", "owner")
