from django.contrib import admin
from .models import Team, TeamMember, TeamInvitation, TeamInvitationToken, UserProfile, TeamAddress

@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
    list_display = ('uuid', 'name', 'owner', 'logto_org_id', 'created_at')
    list_filter = ('created_at',)
    search_fields = ('name', 'uuid', 'owner__username', 'owner__profile__logto_id', 'logto_org_id')
    readonly_fields = ('uuid', 'created_at', 'updated_at')

@admin.register(TeamMember) 
class TeamMemberAdmin(admin.ModelAdmin):
    list_display = ('uuid', 'team', 'user', 'role', 'joined_at')
    list_filter = ('role', 'joined_at')
    search_fields = ('user__username', 'user__profile__logto_id', 'uuid', 'team__name')
    readonly_fields = ('uuid', 'joined_at')

@admin.register(TeamInvitation)
class TeamInvitationAdmin(admin.ModelAdmin):
    list_display = ('uuid', 'team', 'email', 'role', 'status', 'invited_by', 'expires_at')
    list_filter = ('role', 'status', 'expires_at')
    search_fields = ('email', 'uuid', 'team__name', 'invited_by')
    readonly_fields = ('uuid', 'created_at')


@admin.register(TeamInvitationToken)
class TeamInvitationTokenAdmin(admin.ModelAdmin):
    list_display = ('uuid', 'invitation', 'workflow_status', 'expires_at', 'created_at')
    list_filter = ('workflow_status', 'expires_at')
    search_fields = ('uuid', 'invitation__email', 'invitation__team__name')
    readonly_fields = ('uuid', 'created_at')


@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('logto_id', 'user', 'active_team', 'created_at')
    search_fields = ('logto_id', 'user__username', 'active_team__name')


@admin.register(TeamAddress)
class TeamAddressAdmin(admin.ModelAdmin):
    list_display = ('uuid', 'team', 'name', 'address', 'status', 'country_code', 'created_at')
    list_filter = ('status', 'country_code', 'created_at')
    search_fields = ('name', 'address', 'uuid', 'team__name')
    readonly_fields = ('uuid', 'created_at', 'updated_at', 'processed_at')
