Option Strict On
Option Explicit On

Namespace Nexamas.UI.TextInput

    Friend Enum MASTextCompositionAction
        None = 0
        Begin = 1
        Update = 2
        Commit = 3
        Cancel = 4
    End Enum

    ' CONTRACT:
    ' MASTextCompositionCommand is a semantic IME request used by the input pipeline.
    '
    ' It represents composition lifecycle only. It must not directly mutate text state.
    ' The controller decides whether the request changes composition visuals or commits text.
    Friend NotInheritable Class MASTextCompositionCommand

        Private Sub New(action As MASTextCompositionAction,
                        text As String,
                        selectionStart As Integer,
                        selectionLength As Integer)

            Me.Action = action
            Me.Text = text
            Me.SelectionStart = selectionStart
            Me.SelectionLength = selectionLength
        End Sub

        Friend ReadOnly Property Action As MASTextCompositionAction
        Friend ReadOnly Property Text As String
        Friend ReadOnly Property SelectionStart As Integer
        Friend ReadOnly Property SelectionLength As Integer

        Friend Shared Function Begin(Optional text As String = "",
                                     Optional selectionStart As Integer = 0,
                                     Optional selectionLength As Integer = 0) As MASTextCompositionCommand
            Return New MASTextCompositionCommand(MASTextCompositionAction.Begin, text, selectionStart, selectionLength)
        End Function

        Friend Shared Function Update(text As String,
                                      selectionStart As Integer,
                                      selectionLength As Integer) As MASTextCompositionCommand
            Return New MASTextCompositionCommand(MASTextCompositionAction.Update, text, selectionStart, selectionLength)
        End Function

        Friend Shared Function Commit(Optional text As String = Nothing) As MASTextCompositionCommand
            Return New MASTextCompositionCommand(MASTextCompositionAction.Commit, text, 0, 0)
        End Function

        Friend Shared Function Cancel() As MASTextCompositionCommand
            Return New MASTextCompositionCommand(MASTextCompositionAction.Cancel, String.Empty, 0, 0)
        End Function

    End Class

End Namespace
