from books.models import Author, Book, Paper
from django.contrib import admin
from scrobbles.admin import ScrobbleInline


@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "name",
        "openlibrary_id",
        "bio",
        "wikipedia_url",
    )
    ordering = ("-created",)
    search_fields = ("name",)


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "title",
        "author",
        "issue_or_volume",
        "isbn_13",
        "first_publish_year",
        "pages",
    )
    search_fields = ("name",)
    ordering = ("-created",)
    inlines = [
        ScrobbleInline,
    ]

    def issue_or_volume(self, obj):
        return obj.issue_number or obj.volume_number


@admin.register(Paper)
class BookAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "title",
        "subtitle",
        "arxiv_id",
        "first_publish_year",
        "pages",
    )
    search_fields = ("name",)
    ordering = ("-created",)
    inlines = [
        ScrobbleInline,
    ]
