Option Strict On
Option Explicit On

Imports System.Collections.Generic
Imports Nexamas.UI.ThemeStudio

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Verifies that Surface Designer and Theme Studio consume the canonical Surface Material
    ''' registry, slot profiles, and generic slots instead of maintaining a second catalog.
    ''' </summary>
    Friend NotInheritable Class MASSurfaceMaterialDesignerIntegrationAudit
        Private Sub New()
        End Sub

        Friend Shared Function Evaluate() As MASSurfaceMaterialDesignerIntegrationReport
            Dim statuses As New List(Of MASSurfaceMaterialDesignerIntegrationStatus)()
            Dim materials As IReadOnlyList(Of MASSurfaceDesignerMaterialEntry) = MASSurfaceDesigner.GetMaterials()
            Dim profiles As IReadOnlyList(Of MASSurfaceDesignerMaterialProfileEntry) = MASSurfaceDesigner.GetMaterialProfiles()
            Dim slots As IReadOnlyList(Of MASSurfaceDesignerSlotEntry) = MASSurfaceDesigner.GetSlots()
            Dim snapshot As MASThemeStudioSnapshot = MASThemeStudioSnapshotBuilder.Build()
            Dim readiness As MASThemeStudioReadinessReport = MASThemeStudioReadinessGate.Evaluate()

            Dim assignmentCount As Integer = 0
            Dim nativeProfileCount As Integer = 0
            If profiles IsNot Nothing Then
                For Each profile As MASSurfaceDesignerMaterialProfileEntry In profiles
                    If profile Is Nothing Then Continue For
                    assignmentCount += profile.AssignmentCount
                    If profile.HasNativeAssignments Then nativeProfileCount += 1
                    If profile.AssignmentCount <= 0 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.MissingAssignmentDetails)
                Next
            End If

            If materials Is Nothing OrElse materials.Count < 8 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.MissingMaterialCatalog)
            If profiles Is Nothing OrElse profiles.Count < 5 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.MissingProfileCatalog)
            If slots Is Nothing OrElse slots.Count < 10 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.MissingSlotCatalog)
            If nativeProfileCount < 2 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.MissingNativeProfile)
            If assignmentCount < 10 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.MissingAssignmentDetails)
            If snapshot Is Nothing OrElse snapshot.MaterialProfileCount < 5 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.SnapshotMissingProfileFacts)
            If snapshot Is Nothing OrElse snapshot.SlotCount < 10 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.SnapshotMissingSlotFacts)

            If readiness Is Nothing OrElse readiness.MaterialProfileCount < 5 OrElse readiness.SlotCount < 10 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.GateMissingNativeProfileProtection)

            If statuses.Count = 0 Then statuses.Add(MASSurfaceMaterialDesignerIntegrationStatus.Ready)

            Return New MASSurfaceMaterialDesignerIntegrationReport(
                materialCount:=If(materials Is Nothing, 0, materials.Count),
                materialProfileCount:=If(profiles Is Nothing, 0, profiles.Count),
                slotCount:=If(slots Is Nothing, 0, slots.Count),
                assignmentCount:=assignmentCount,
                nativeProfileCount:=nativeProfileCount,
                statuses:=statuses,
                notes:="Designer integration projects material definitions, slot profiles, slot assignments, and generic slots from canonical owners.")
        End Function

    End Class

End Namespace
