Option Strict On
Option Explicit On

Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Linq

Namespace Nexamas.UI.Verification

    ''' <summary>
    ''' Release-evidence immutable snapshot used by dashboards, CI tools, and product demos to display the real render-verification asset set.
    ''' It contains generated PNG paths and comparison facts, not internal runner objects.
    ''' Seeded baselines are separated from passed entries so product UI cannot auto-approve new artifacts.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Advanced)>
    Public NotInheritable Class MASRenderVerificationSnapshot
        Private ReadOnly _entries As IReadOnlyList(Of MASRenderVerificationEntry)

        Friend Sub New(outputDirectory As String,
                       baselineDirectory As String,
                       currentDirectory As String,
                       differenceDirectory As String,
                       entries As IEnumerable(Of MASRenderVerificationEntry))
            Me.OutputDirectory = If(outputDirectory, String.Empty)
            Me.BaselineDirectory = If(baselineDirectory, String.Empty)
            Me.CurrentDirectory = If(currentDirectory, String.Empty)
            Me.DifferenceDirectory = If(differenceDirectory, String.Empty)
            Me.CapturedAtUtc = Nexamas.UI.Timing.MASTimeProvider.UtcNow()
            _entries = If(entries, Array.Empty(Of MASRenderVerificationEntry)()).Where(Function(entry) entry IsNot Nothing).ToArray()
        End Sub

        Public ReadOnly Property OutputDirectory As String
        Public ReadOnly Property BaselineDirectory As String
        Public ReadOnly Property CurrentDirectory As String
        Public ReadOnly Property DifferenceDirectory As String
        Public ReadOnly Property CapturedAtUtc As DateTime

        Public ReadOnly Property Entries As IReadOnlyList(Of MASRenderVerificationEntry)
            Get
                Return _entries
            End Get
        End Property

        Public ReadOnly Property EntryCount As Integer
            Get
                Return _entries.Count
            End Get
        End Property

        Public ReadOnly Property PassedCount As Integer
            Get
                Return Global.System.Linq.Enumerable.Count(_entries, Function(entry) entry.Passed)
            End Get
        End Property

        Public ReadOnly Property SeededCount As Integer
            Get
                Return Global.System.Linq.Enumerable.Count(_entries, Function(entry) entry.RequiresApproval)
            End Get
        End Property

        Public ReadOnly Property FailedCount As Integer
            Get
                Return Global.System.Linq.Enumerable.Count(_entries, Function(entry) entry.Outcome = MASRenderVerificationOutcome.Failed)
            End Get
        End Property

        Public ReadOnly Property InvalidCount As Integer
            Get
                Return Global.System.Linq.Enumerable.Count(_entries, Function(entry) entry.Invalid)
            End Get
        End Property

        Public ReadOnly Property ReviewCount As Integer
            Get
                Return SeededCount + FailedCount + InvalidCount
            End Get
        End Property

        Public ReadOnly Property RequiresApproval As Boolean
            Get
                Return SeededCount > 0
            End Get
        End Property

        Public ReadOnly Property Passed As Boolean
            Get
                Return EntryCount > 0 AndAlso ReviewCount = 0 AndAlso PassedCount = EntryCount
            End Get
        End Property

        Public ReadOnly Property HasPreviewImages As Boolean
            Get
                Return _entries.Any(Function(entry) entry.HasBaselineImage AndAlso entry.HasCurrentImage)
            End Get
        End Property
    End Class

End Namespace
