from .models import TokenCache
from django.contrib import admin
from .models import (
    Voucher,
    UserVoucher,
    VoucherPullFailure,
    Brand,
    VoucherPurchaseHistory
)

@admin.register(TokenCache)
class TokenCacheAdmin(admin.ModelAdmin):
    list_display = ['token', 'created_at']
    
# 4. (Optional) Management Command to Pull Voucher
# python manage.py pull_voucher --brand Bata4xfRrUnT46Uv4iol --amount 100 --qty 1 --orderid test-001


@admin.register(Voucher)
class VoucherAdmin(admin.ModelAdmin):
    list_display = ('voucher_code', 'brand', 'value', 'status', 'expiry_date', 'created_at')
    search_fields = ('voucher_code', 'product_name', 'voucher_name')
    list_filter = ('brand', 'status', 'expiry_date')
    ordering = ('-created_at',)

@admin.register(UserVoucher)
class UserVoucherAdmin(admin.ModelAdmin):
    list_display = ('user', 'voucher', 'order_id', 'assigned_at')
    search_fields = ('user__email', 'voucher__voucher_code', 'order_id')
    list_filter = ('assigned_at',)
    ordering = ('-assigned_at',)

@admin.register(VoucherPullFailure)
class VoucherPullFailureAdmin(admin.ModelAdmin):
    list_display = ('order_id', 'brand_code', 'denomination', 'quantity', 'reason', 'created_at')
    search_fields = ('order_id', 'brand_code')
    list_filter = ('created_at',)
    ordering = ('-created_at',)

@admin.register(Brand)
class BrandAdmin(admin.ModelAdmin):
    list_display = ('name', 'product_code')
    search_fields = ('name', 'product_code')

@admin.register(VoucherPurchaseHistory)
class VoucherPurchaseHistoryAdmin(admin.ModelAdmin):
    list_display = ('order_id', 'brand', 'denomination', 'quantity', 'created_at')
    search_fields = ('order_id', 'brand__name')
    list_filter = ('created_at',)
    ordering = ('-created_at',)
