from django.contrib import admin
from pricemon.models import PriceAlert, PriceSnapshot, PriceWatcher


@admin.register(PriceWatcher)
class PriceWatcherAdmin(admin.ModelAdmin):
    list_display = [
        'name',
        'url',
        'initial_price',
        'last_price',
        'last_checked_at',
        'enabled',
        'check_interval_hours',
    ]
    list_filter = ['enabled', 'check_interval_hours']
    search_fields = ['name', 'url']


@admin.register(PriceSnapshot)
class PriceSnapshotAdmin(admin.ModelAdmin):
    list_display = ['watcher', 'price', 'raw_text', 'error', 'checked_at']
    list_filter = ['watcher']
    readonly_fields = ['checked_at']


@admin.register(PriceAlert)
class PriceAlertAdmin(admin.ModelAdmin):
    list_display = ['watcher', 'old_price', 'new_price', 'drop_pct', 'dismissed', 'created_at']
    list_filter = ['dismissed', 'watcher']
    readonly_fields = ['created_at']
