from django.contrib import admin
from .models import Category, Medicine, Batch, StockTransaction, Supplier, Faktur, AppSetting

# DN-WRS Branding
admin.site.site_header = "DN-WRS Admin"
admin.site.site_title = "DN-WRS Portal"
admin.site.index_title = "Selamat Datang di Manajemen DN-WRS"

@admin.register(AppSetting)
class AppSettingAdmin(admin.ModelAdmin):
    list_display = ('app_name', 'app_email', 'app_phone')
    
    def has_add_permission(self, request):
        # Allow only one instance of AppSetting
        if self.model.objects.exists():
            return False
        return True

@admin.register(Supplier)
class SupplierAdmin(admin.ModelAdmin):
    list_display = ('name', 'contact_person', 'phone')
    search_fields = ('name',)

@admin.register(Faktur)
class FakturAdmin(admin.ModelAdmin):
    list_display = ('faktur_number', 'supplier', 'date', 'faktur_type')
    list_filter = ('faktur_type', 'date')
    search_fields = ('faktur_number',)

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

@admin.register(Medicine)
class MedicineAdmin(admin.ModelAdmin):
    list_display = ('name', 'category', 'sku', 'unit', 'total_stock', 'status')
    search_fields = ('name', 'sku')
    list_filter = ('category', 'unit')

@admin.register(Batch)
class BatchAdmin(admin.ModelAdmin):
    list_display = ('medicine', 'batch_number', 'expiry_date', 'quantity', 'is_expired')
    list_filter = ('expiry_date',)
    search_fields = ('batch_number', 'medicine__name')

@admin.register(StockTransaction)
class StockTransactionAdmin(admin.ModelAdmin):
    list_display = ('medicine', 'transaction_type', 'quantity', 'created_at')
    list_filter = ('transaction_type', 'created_at')
