from django.contrib import admin
from .models import Contact, SkipTraceJob, SkipTraceResult


class SkipTraceResultInline(admin.TabularInline):
    model = SkipTraceResult
    extra = 0
    readonly_fields = ('contact', 'found_address', 'found_phone', 'is_found')
    can_delete = False


@admin.register(SkipTraceJob)
class SkipTraceJobAdmin(admin.ModelAdmin):
    list_display = ('id', 'original_file_name', 'status', 'created_at')
    list_filter = ('status',)
    inlines = [SkipTraceResultInline]


@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
    list_display = ('first_name', 'last_name', 'address', 'city', 'state', 'zip_code')
    search_fields = ('first_name', 'last_name', 'address')


@admin.register(SkipTraceResult)
class SkipTraceResultAdmin(admin.ModelAdmin):
    list_display = ('job', 'contact', 'is_found')
    list_filter = ('is_found',)
    search_fields = ('contact__first_name', 'contact__last_name')
