from django.contrib import admin
from .models import InstallationAssignment, InstallationReport, InstallationPhoto, InstallationItemChange


@admin.register(InstallationAssignment)
class InstallationAssignmentAdmin(admin.ModelAdmin):
    list_display = ('process_instance', 'installer', 'scheduled_date', 'created')
    search_fields = ('process_instance__code', 'installer__username', 'installer__first_name', 'installer__last_name')
    list_filter = ('scheduled_date',)


class InstallationPhotoInline(admin.TabularInline):
    model = InstallationPhoto
    extra = 0


class InstallationItemChangeInline(admin.TabularInline):
    model = InstallationItemChange
    extra = 0


@admin.register(InstallationReport)
class InstallationReportAdmin(admin.ModelAdmin):
    list_display = ('assignment', 'visited_date', 'new_water_meter_serial', 'seal_number', 'is_meter_suspicious', 'approved', 'created')
    list_filter = ('is_meter_suspicious', 'approved', 'visited_date')
    search_fields = ('assignment__process_instance__code', 'new_water_meter_serial', 'seal_number')
    inlines = [InstallationPhotoInline, InstallationItemChangeInline]


@admin.register(InstallationPhoto)
class InstallationPhotoAdmin(admin.ModelAdmin):
    list_display = ('report', 'created')


@admin.register(InstallationItemChange)
class InstallationItemChangeAdmin(admin.ModelAdmin):
    list_display = ('report', 'item', 'change_type', 'quantity', 'unit_price', 'total_price', 'created')
    list_filter = ('change_type',)

