from django.contrib import admin
from scrobbles.admin import ScrobbleInline
from workouts.models import (
    Exercise,
    WorkoutImport,
    WorkoutRoutine,
    WorkoutRoutineExercise,
)


@admin.register(Exercise)
class ExerciseAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = ("uuid", "name", "level", "equipment", "category", "primary_muscles")
    ordering = ("name",)
    search_fields = ("name", "primary_muscles", "secondary_muscles")


class WorkoutRoutineExerciseInline(admin.TabularInline):
    model = WorkoutRoutineExercise
    extra = 0


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


@admin.register(WorkoutImport)
class WorkoutImportAdmin(admin.ModelAdmin):
    list_display = (
        "uuid",
        "user",
        "original_filename",
        "processing_started",
        "processed_finished",
        "process_count",
    )
    ordering = ("-created",)
    readonly_fields = (
        "uuid",
        "created",
        "modified",
        "processing_started",
        "processed_finished",
        "process_log",
        "process_count",
        "error_log",
        "file_hash",
    )
