from django.contrib import admin
from .models import Team, TeamMembership, Bookmark, BookmarkShare, Extraction, Summary, APIToken

class TeamMembershipInline(admin.TabularInline):
    model = TeamMembership
    extra = 1

@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
    list_display = ('name', 'created_at', 'updated_at')
    inlines = [TeamMembershipInline]

@admin.register(Bookmark)
class BookmarkAdmin(admin.ModelAdmin):
    list_display = ('title', 'url', 'user', 'is_favorite', 'created_at')
    list_filter = ('is_favorite', 'created_at', 'user')
    search_fields = ('title', 'url', 'notes')

@admin.register(BookmarkShare)
class BookmarkShareAdmin(admin.ModelAdmin):
    list_display = ('bookmark', 'team', 'shared_by', 'shared_at')
    list_filter = ('team', 'shared_at')

@admin.register(Extraction)
class ExtractionAdmin(admin.ModelAdmin):
    list_display = ('bookmark', 'extracted_at')

@admin.register(Summary)
class SummaryAdmin(admin.ModelAdmin):
    list_display = ('bookmark', 'generated_at')

@admin.register(APIToken)
class APITokenAdmin(admin.ModelAdmin):
    list_display = ('name', 'user', 'created_at', 'last_used_at', 'is_active')
    list_filter = ('is_active', 'created_at', 'last_used_at')
    search_fields = ('name', 'user__username', 'token')
    readonly_fields = ('token', 'created_at', 'last_used_at')
