from django.contrib import admin
from .models import Plant, Category, Product, Inventory, Machine, WorkOrder, Inspection

@admin.register(Plant)
class PlantAdmin(admin.ModelAdmin):
    list_display = ('name', 'location')
    search_fields = ('name', 'location')

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name',)

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ('name', 'sku', 'category')
    search_fields = ('name', 'sku')
    list_filter = ('category',)

@admin.register(Inventory)
class InventoryAdmin(admin.ModelAdmin):
    list_display = ('product', 'plant', 'quantity', 'lot_number')
    list_filter = ('plant', 'product')
    search_fields = ('lot_number',)

@admin.register(Machine)
class MachineAdmin(admin.ModelAdmin):
    list_display = ('name', 'plant', 'status', 'last_maintenance')
    list_filter = ('plant', 'status')
    search_fields = ('name',)

class InspectionInline(admin.TabularInline):
    model = Inspection
    extra = 1

@admin.register(WorkOrder)
class WorkOrderAdmin(admin.ModelAdmin):
    list_display = ('order_number', 'plant', 'product', 'quantity', 'status', 'start_date')
    list_filter = ('plant', 'status', 'product')
    search_fields = ('order_number',)
    inlines = [InspectionInline]

@admin.register(Inspection)
class InspectionAdmin(admin.ModelAdmin):
    list_display = ('work_order', 'result', 'inspector', 'timestamp')
    list_filter = ('result', 'timestamp')