from django.contrib import admin
from .models import Document, DocumentSegment, Organization, Risk, Control

class DocumentSegmentInline(admin.StackedInline):
    model = DocumentSegment
    extra = 1
    ordering = ['order']
    fields = ('segment_type', 'content', 'order')
    
class DocumentAdmin(admin.ModelAdmin):
    inlines = [DocumentSegmentInline]
    list_display = ('organization', 'created_at', 'modified_at')
    search_fields = ['organization__name']
    readonly_fields = ('created_at', 'modified_at')
    
class OrganizationAdmin(admin.ModelAdmin):
    list_display = ('name', 'email', 'industry_sector')
    search_fields = ['name', 'email']

class RiskAdmin(admin.ModelAdmin):
    ordering = ['risk_id']
    list_display = ['risk_id','risk_name','category']

class ControlAdmin(admin.ModelAdmin):
    list_display = ('risk', 'safeguard', 'weight')
    search_fields = ('risk__risk_name', 'safeguard')
    list_filter = ('risk', 'weight')


admin.site.register(Document, DocumentAdmin)
admin.site.register(Organization, OrganizationAdmin)
admin.site.register(Risk ,RiskAdmin)
admin.site.register(Control, ControlAdmin)
