Imports SkiaSharp

Namespace Nexamas.UI.Verification

    ''' <summary>
    ''' Describes one persisted screenshot snapshot generated by the render verification runner.
    ''' Hashes are computed from encoded PNG bytes so reports can detect accidental baseline replacement.
    ''' </summary>
    Friend NotInheritable Class MASRenderSnapshotResult

        Private Sub New(scenario As MASRenderVerificationScenario, path As String, width As Integer, height As Integer, hash As String)
            Me.Scenario = scenario
            Me.Path = If(path, String.Empty)
            Me.Width = width
            Me.Height = height
            Me.Hash = If(hash, String.Empty)
            Me.CapturedAtUtc = Nexamas.UI.Timing.MASTimeProvider.UtcNow()
        End Sub

        Friend ReadOnly Property Scenario As MASRenderVerificationScenario
        Friend ReadOnly Property Path As String
        Friend ReadOnly Property Width As Integer
        Friend ReadOnly Property Height As Integer
        Friend ReadOnly Property Hash As String
        Friend ReadOnly Property CapturedAtUtc As DateTime

        Friend Shared Function FromBitmap(scenario As MASRenderVerificationScenario, path As String, bitmap As SKBitmap) As MASRenderSnapshotResult
            If bitmap Is Nothing Then Throw New ArgumentNullException(NameOf(bitmap))
            Return New MASRenderSnapshotResult(scenario, path, bitmap.Width, bitmap.Height, MASRenderBaselineStore.ComputeStableHash(bitmap))
        End Function

        Friend Shared Function FromEncodedData(scenario As MASRenderVerificationScenario,
                                               path As String,
                                               width As Integer,
                                               height As Integer,
                                               hash As String) As MASRenderSnapshotResult
            Return New MASRenderSnapshotResult(scenario, path, width, height, hash)
        End Function

        Friend Shared Function FromPersistedFile(scenario As MASRenderVerificationScenario,
                                                 path As String,
                                                 width As Integer,
                                                 height As Integer,
                                                 hash As String) As MASRenderSnapshotResult
            Return New MASRenderSnapshotResult(scenario, path, width, height, hash)
        End Function

    End Class

End Namespace
