Option Strict On
Option Explicit On

Imports System.Collections.Generic

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Builds the first-pass inventory of current surface-treatment ownership.
    ''' This inventory deliberately records current facts; it does not migrate consumers,
    ''' draw controls, resolve layout, run RenderVerification, or create public API. Interactive control surfaces are intentionally outside the Surface Treatment scope.
    ''' </summary>
    Friend NotInheritable Class MASSurfaceTreatmentOwnershipInventoryBuilder

        Private Sub New()
        End Sub

        Friend Shared Function BuildCurrentSurfaceTreatmentInventory() As MASSurfaceTreatmentOwnershipReport
            Dim entries As New List(Of MASSurfaceTreatmentInventoryEntry)()

            For Each consumerKind As MASSurfaceTreatmentConsumerKind In MASSurfaceTreatmentConsumerCatalog.CurrentOwnershipConsumers()
                entries.Add(BuildInventoryEntry(consumerKind))
            Next

            ' Surface-only scope correction: Button, input, dropdown, list-item, tile-item, and DataGrid internals are not
            ' Surface Treatment consumers. They stay under their dedicated interaction visual policies.
            Return New MASSurfaceTreatmentOwnershipReport(
                name:="Surface Treatment Ownership Inventory & Governance",
                entries:=entries.ToArray(),
                materialProfiles:=MASSurfaceTreatmentMaterialProfileCatalog.RegisteredProfiles())
        End Function

        Private Shared Function BuildInventoryEntry(consumerKind As MASSurfaceTreatmentConsumerKind) As MASSurfaceTreatmentInventoryEntry
            Select Case consumerKind
                Case MASSurfaceTreatmentConsumerKind.PanelShellSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="PanelShell / PanelShellDialog / MessageBox / FilePicker / FileExplorer",
                        architectureMaterialRoleName:="Dialog",
                        currentMaterialSource:="MASSurfaceVisualStyleIds.PlatformDialogFrame -> MASSurfaceMaterialRegistry",
                        currentFrameSource:="MASSurfaceVisualStyleIds.PlatformDialogFrame -> MASSurfaceFrameIds.PlatformDefault",
                        currentFrameStrengthSource:="MASSurfaceFrameStrength.Level1-Level6 through VisualSurfaceFrame",
                        defaultMaterialKey:=MASSurfaceMaterialIds.PlatformDefault,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeBound,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="This is the current canonical complete surface style and must remain visually unchanged.")

                Case MASSurfaceTreatmentConsumerKind.ApplicationChromeSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="Application startup shell / ready form surface",
                        architectureMaterialRoleName:="Shell",
                        currentMaterialSource:="MASSurfaceVisualStyleIds.PlatformDialogFrame or PlatformDefault material through startup shell rendering",
                        currentFrameSource:="MASSurfaceFrameIds.PlatformDefault",
                        currentFrameStrengthSource:="VisualSurfaceFrame strength levels where the shell consumes reusable frames",
                        defaultMaterialKey:=MASSurfaceMaterialIds.PlatformDefault,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeBound,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Application shell consumers are already close to the official style path.")

                Case MASSurfaceTreatmentConsumerKind.ProgressSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="ProgressBar / OperationProgressBox container surface",
                        architectureMaterialRoleName:="Control",
                        currentMaterialSource:="ContainerSurfaceMaterialKey resolved through MASSurfaceMaterialRegistry",
                        currentFrameSource:="Progress-specific container chrome; not yet a material-paired frame profile",
                        currentFrameStrengthSource:="MASSurfaceStrength and component-local progress state",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeTinted,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Progress already accepts a material key, but frame pairing still needs formal treatment governance.")

                Case MASSurfaceTreatmentConsumerKind.BackgroundSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="Application background / form surface",
                        architectureMaterialRoleName:="Background",
                        currentMaterialSource:="MASBackground default painter; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="No frame for background surface",
                        currentFrameStrengthSource:="Surface strength only; frame repaint is not applicable",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeBound,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Auto keeps the current background painter; explicit material-key selection is routed through the official material registry.")

                Case MASSurfaceTreatmentConsumerKind.CardSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="Card / elevated content surfaces",
                        architectureMaterialRoleName:="Panel",
                        currentMaterialSource:="CardPainter default path; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="Premium elevated shadow is preserved; explicit material changes the surface fill only",
                        currentFrameStrengthSource:="Elevation/appearance profiles are preserved for Auto",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeTinted,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Card Auto preserves the existing elevated look; explicit material keys route through the official runtime material helper.")

                Case MASSurfaceTreatmentConsumerKind.ToastSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="Toast panel surface",
                        architectureMaterialRoleName:="Toast",
                        currentMaterialSource:="MASSurfaceFramePainter by default; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="Toast overlay frame remains owned by existing toast renderer; explicit material changes the surface fill only",
                        currentFrameStrengthSource:="Toast-specific overlay/elevation role is preserved for Auto",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeTinted,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Toast Auto keeps the existing overlay panel; explicit material keys use the official resolver while text, accent, lifetime, and close/action behavior stay unchanged.")

                Case MASSurfaceTreatmentConsumerKind.TooltipSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="Tooltip surface",
                        architectureMaterialRoleName:="Tooltip",
                        currentMaterialSource:="TooltipRenderer default drawing; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="Tooltip-local arrow/border chrome remains local; explicit material changes the panel surface fill only",
                        currentFrameStrengthSource:="Tooltip-specific lightweight overlay drawing is preserved for Auto",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeTinted,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Tooltip Auto keeps the existing direct drawing; explicit material keys do not change hit testing, timing, or FloatRuntime ownership.")

                Case MASSurfaceTreatmentConsumerKind.TopBarSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="TopBar chrome surface",
                        architectureMaterialRoleName:="TopBar",
                        currentMaterialSource:="TopBarPainter default acrylic bar; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="TopBar shadow and chrome overlays remain in the existing painter",
                        currentFrameStrengthSource:="Application chrome strength policy; Auto preserves current bar rendering",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeBound,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="TopBar Auto keeps the current premium acrylic bar; explicit material keys only replace the surface fill through the official runtime helper.")

                Case MASSurfaceTreatmentConsumerKind.ToolbarSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="Toolbar strip surface",
                        architectureMaterialRoleName:="Toolbar",
                        currentMaterialSource:="Toolbar layout container; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="No separate Toolbar frame route in this pass",
                        currentFrameStrengthSource:="Application chrome strength policy; Auto preserves the current transparent/layout-only toolbar behavior",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeTinted,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="Toolbar Auto remains visually unchanged; explicit material keys draw an owned toolbar strip surface before item layout.")

                Case MASSurfaceTreatmentConsumerKind.GroupBoxSurface
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:="GroupBox container surface",
                        architectureMaterialRoleName:="Panel",
                        currentMaterialSource:="MASGroupBox renderer default path; explicit material route uses VisualSurface runtime surface visual application",
                        currentFrameSource:="Existing MASGroupBox frame/border recipe remains owned by MASGroupBox renderer",
                        currentFrameStrengthSource:="MASGroupBox border strength remains the public container frame-strength gateway",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeTinted,
                        status:=MASSurfaceTreatmentOwnershipStatus.SurfaceVisualOwned,
                        consumesVisualSurface:=True,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=True,
                        notes:="GroupBox Auto preserves the current container visual; explicit material keys change the container surface fill only and do not affect child controls.")

                Case Else
                    Return NewEntry(
                        consumerKind:=consumerKind,
                        consumerName:=MASSurfaceTreatmentConsumerCatalog.ConsumerDisplayName(consumerKind),
                        architectureMaterialRoleName:="Surface",
                        currentMaterialSource:="Not part of the current ownership catalog.",
                        currentFrameSource:="Not part of the current ownership catalog.",
                        currentFrameStrengthSource:="Not part of the current ownership catalog.",
                        defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                        defaultFrameKey:=MASSurfaceFrameIds.PlatformDefault,
                        themeInfluenceMode:=MASSurfaceTreatmentThemeInfluenceMode.ThemeBound,
                        status:=MASSurfaceTreatmentOwnershipStatus.DocumentedLegacyPainterSurface,
                        consumesVisualSurface:=False,
                        requiresCapturedMaterial:=False,
                        requiresMaterialFramePairing:=False,
                        notes:="This consumer is not emitted by MASSurfaceTreatmentConsumerCatalog.CurrentOwnershipConsumers().")
            End Select
        End Function

        Private Shared Function NewEntry(consumerKind As MASSurfaceTreatmentConsumerKind,
                                         consumerName As String,
                                         architectureMaterialRoleName As String,
                                         currentMaterialSource As String,
                                         currentFrameSource As String,
                                         currentFrameStrengthSource As String,
                                         defaultMaterialKey As String,
                                         defaultFrameKey As String,
                                         themeInfluenceMode As MASSurfaceTreatmentThemeInfluenceMode,
                                         status As MASSurfaceTreatmentOwnershipStatus,
                                         consumesVisualSurface As Boolean,
                                         requiresCapturedMaterial As Boolean,
                                         requiresMaterialFramePairing As Boolean,
                                         notes As String) As MASSurfaceTreatmentInventoryEntry

            Return New MASSurfaceTreatmentInventoryEntry(
                consumerKind:=consumerKind,
                consumerName:=consumerName,
                architectureMaterialRoleName:=architectureMaterialRoleName,
                currentMaterialSource:=currentMaterialSource,
                currentFrameSource:=currentFrameSource,
                currentFrameStrengthSource:=currentFrameStrengthSource,
                defaultMaterialKey:=defaultMaterialKey,
                defaultFrameKey:=defaultFrameKey,
                themeInfluenceMode:=themeInfluenceMode,
                status:=status,
                consumesVisualSurface:=consumesVisualSurface,
                requiresCapturedMaterial:=requiresCapturedMaterial,
                requiresMaterialFramePairing:=requiresMaterialFramePairing,
                preservesCurrentVisualShape:=True,
                notes:=notes)
        End Function

    End Class

End Namespace
