from django.contrib import admin

from . import models


@admin.register(models.CostCategory)
class CostCategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'merchant', 'unique_key', 'name', 'parent', 'created_at')
    search_fields = ('name', 'unique_key')
    list_filter = ('merchant', 'created_at')
    ordering = ('merchant', 'name')


@admin.register(models.CostEntry)
class CostEntryAdmin(admin.ModelAdmin):
    list_display = (
        'id', 'merchant', 'category', 'amount', 'unit_amount', 'quantity',
        'unit_name', 'occurred_at', 'operator', 'source_module', 'source_id',
        'created_at',
    )
    search_fields = ('category__name', 'source_module', 'source_id')
    list_filter = ('merchant', 'category', 'occurred_at', 'source_module', 'created_at')
    ordering = ('-occurred_at', '-created_at')