from django.contrib import admin

from .models import FertilizerProfile, Material, PesticideProfile, StockTransaction


class FertilizerProfileInline(admin.StackedInline):
    model = FertilizerProfile
    extra = 0


class PesticideProfileInline(admin.StackedInline):
    model = PesticideProfile
    extra = 0


@admin.register(Material)
class MaterialAdmin(admin.ModelAdmin):
    list_display = ['name', 'material_type', 'maker', 'stock_unit', 'is_active']
    list_filter = ['material_type', 'is_active']
    search_fields = ['name', 'maker']
    inlines = [FertilizerProfileInline, PesticideProfileInline]


@admin.register(StockTransaction)
class StockTransactionAdmin(admin.ModelAdmin):
    list_display = ['material', 'transaction_type', 'quantity', 'occurred_on']
    list_filter = ['transaction_type', 'occurred_on']
    search_fields = ['material__name']
