Option Strict On
Option Explicit On

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Friend-only proof that MASKanbanBoard can snapshot/restore visual board
    ''' layout and card order without becoming task storage, workflow runtime, or
    ''' external provider infrastructure.
    ''' </summary>
    Friend NotInheritable Class MASKanbanBoardPersistenceGate
        Private Sub New()
        End Sub

        Friend Shared Function Passes() As Boolean
            Try
                If Not MASKanbanBoardPolicy.HasBoardSnapshotPersistencePath() Then Return False
                If Not MASKanbanBoardPolicy.HasCardReorderPath() Then Return False

                Dim board As MASKanbanBoard = MASKanbanBoard.Create("Gate board")
                board.AddColumn("todo", "Todo")
                board.AddColumn("doing", "Doing")
                board.AddCard("todo", "a", "A", "Alpha", "1")
                board.AddCard("todo", "b", "B", "Beta", "2")
                board.AddCard("doing", "c", "C", "Gamma", "3")
                If Not board.MoveCardToIndex("b", "todo", 0) Then Return False
                If Not board.SelectCard("b") Then Return False

                Dim snapshot As MASKanbanBoardSnapshot = board.CreateBoardSnapshot()
                If snapshot Is Nothing Then Return False
                If snapshot.Columns.Count <> 2 Then Return False
                If snapshot.SelectedCardKey <> "b" Then Return False
                If snapshot.Columns(0).Cards.Count <> 2 Then Return False
                If snapshot.Columns(0).Cards(0).Key <> "b" Then Return False

                Dim restored As MASKanbanBoard = MASKanbanBoard.Create("Empty")
                If Not restored.RestoreBoardSnapshot(snapshot) Then Return False
                If restored.ColumnCount <> 2 Then Return False
                If restored.CardCount <> 3 Then Return False
                If restored.SelectedCardKey <> "b" Then Return False
                If restored.GetCardKeys("todo")(0) <> "b" Then Return False
                If Not restored.HasBoardSnapshotForTests() Then Return False

                restored.ResetBoardViewport()
                If restored.CreateBoardSnapshot().Columns.Count <> 2 Then Return False
                Return True
            Catch ex As System.Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASKanbanBoardPersistenceGate")
                Return False
            End Try
        End Function
    End Class

End Namespace
