Option Strict On
Option Explicit On

Imports System.Collections.Generic
Imports System.Linq

Namespace Nexamas.UI.Localization

    ''' <summary>
    ''' Immutable readiness report for the Phase 6 Localization / RTL product layer.
    ''' </summary>
    Friend NotInheritable Class MASLocalizationReadinessReport
        Friend Sub New(cultureCount As Integer,
                       localizedStringCount As Integer,
                       formatSampleCount As Integer,
                       expansionSampleCount As Integer,
                       hasRightToLeftCulture As Boolean,
                       hasMirroredLayoutCulture As Boolean,
                       findings As IEnumerable(Of MASLocalizationReadinessFinding))
            Me.CultureCount = Math.Max(0, cultureCount)
            Me.LocalizedStringCount = Math.Max(0, localizedStringCount)
            Me.FormatSampleCount = Math.Max(0, formatSampleCount)
            Me.ExpansionSampleCount = Math.Max(0, expansionSampleCount)
            Me.HasRightToLeftCulture = hasRightToLeftCulture
            Me.HasMirroredLayoutCulture = hasMirroredLayoutCulture
            Me.Findings = CopyFindings(findings)
        End Sub

        Friend ReadOnly Property CultureCount As Integer
        Friend ReadOnly Property LocalizedStringCount As Integer
        Friend ReadOnly Property FormatSampleCount As Integer
        Friend ReadOnly Property ExpansionSampleCount As Integer
        Friend ReadOnly Property HasRightToLeftCulture As Boolean
        Friend ReadOnly Property HasMirroredLayoutCulture As Boolean
        Friend ReadOnly Property Findings As IReadOnlyList(Of MASLocalizationReadinessFinding)

        Friend ReadOnly Property ErrorCount As Integer
            Get
                Return Global.System.Linq.Enumerable.Count(Findings, Function(finding) finding IsNot Nothing AndAlso finding.Severity = MASLocalizationReadinessSeverity.[Error])
            End Get
        End Property

        Friend ReadOnly Property WarningCount As Integer
            Get
                Return Global.System.Linq.Enumerable.Count(Findings, Function(finding) finding IsNot Nothing AndAlso finding.Severity = MASLocalizationReadinessSeverity.Warning)
            End Get
        End Property

        Friend ReadOnly Property ReadyForPhase6Foundation As Boolean
            Get
                Return ErrorCount = 0 AndAlso CultureCount >= 3 AndAlso LocalizedStringCount >= 3 AndAlso FormatSampleCount >= CultureCount AndAlso ExpansionSampleCount >= 3 AndAlso HasRightToLeftCulture AndAlso HasMirroredLayoutCulture
            End Get
        End Property

        Private Shared Function CopyFindings(items As IEnumerable(Of MASLocalizationReadinessFinding)) As IReadOnlyList(Of MASLocalizationReadinessFinding)
            Dim list As New List(Of MASLocalizationReadinessFinding)()
            If items IsNot Nothing Then list.AddRange(items)
            Return list.AsReadOnly()
        End Function
    End Class

End Namespace
