from django.contrib import admin
from drinks.models import (
    Beer,
    BeerProducer,
    BeerStyle,
    Coffee,
    CoffeeRoaster,
    Drink,
    Wine,
    WineGrape,
    WineProducer,
    WineRegion,
)
from scrobbles.admin import ScrobbleInline


class BeerInline(admin.TabularInline):
    model = Beer
    extra = 0


@admin.register(BeerStyle)
class BeerStyleAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    search_fields = ("name",)


@admin.register(BeerProducer)
class BeerProducerAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    search_fields = ("name",)


@admin.register(Beer)
class BeerAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "uuid",
        "title",
    )
    raw_id_fields = ("styles", "producer")
    ordering = ("-created",)
    search_fields = ("title",)
    inlines = [
        ScrobbleInline,
    ]


@admin.register(WineGrape)
class WineGrapeAdmin(admin.ModelAdmin):
    search_fields = ("name",)


@admin.register(WineRegion)
class WineRegionAdmin(admin.ModelAdmin):
    search_fields = ("name", "country")


@admin.register(WineProducer)
class WineProducerAdmin(admin.ModelAdmin):
    search_fields = ("name",)


@admin.register(Wine)
class WineAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "uuid",
        "title",
        "wine_type",
        "vintage",
    )
    raw_id_fields = ("grapes", "region", "producer")
    ordering = ("-created",)
    search_fields = ("title",)
    list_filter = ("wine_type",)
    inlines = [
        ScrobbleInline,
    ]


@admin.register(CoffeeRoaster)
class CoffeeRoasterAdmin(admin.ModelAdmin):
    search_fields = ("name",)


@admin.register(Coffee)
class CoffeeAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "uuid",
        "title",
        "origin",
    )
    raw_id_fields = ("roaster",)
    ordering = ("-created",)
    search_fields = ("title",)
    inlines = [
        ScrobbleInline,
    ]


@admin.register(Drink)
class DrinkAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "uuid",
        "title",
    )
    ordering = ("-created",)
    search_fields = ("title",)
    inlines = [
        ScrobbleInline,
    ]
