from django.contrib import admin
from music.models import Album, Artist, Track
from scrobbles.admin import ScrobbleInline


@admin.register(Album)
class AlbumAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "name",
        "year",
        "artist",
        "theaudiodb_genre",
        "theaudiodb_mood",
        "musicbrainz_id",
    )
    raw_id_fields = ("album_artist",)
    list_filter = (
        "theaudiodb_score",
        "theaudiodb_genre",
    )
    ordering = ("-created",)
    search_fields = ("name",)
    filter_horizontal = [
        "artists",
    ]


@admin.register(Artist)
class ArtistAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "name",
        "theaudiodb_mood",
        "theaudiodb_genre",
        "musicbrainz_id",
    )
    list_filter = (
        "theaudiodb_mood",
        "theaudiodb_genre",
    )
    search_fields = ("name",)
    ordering = ("-created",)


@admin.register(Track)
class TrackAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "title",
        "primary_album",
        "artist",
        "musicbrainz_id",
    )
    raw_id_fields = ("artist_fk", "artists", "albums", "album")
    search_fields = ("title",)
    ordering = ("-created",)
    filter_horizontal = [
        "albums",
        "artists",
    ]
    inlines = [
        ScrobbleInline,
    ]
