Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.Logging

Namespace Modules.IDB
    Public Class CheckInFile
        Inherits BaseMethod

        Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
            MyBase.New(pLogConfig, pChannel)
        End Sub

        Public Async Function RunAsync(pObjectId As Long, Optional pOptions As Options.CheckOutInOptions = Nothing) As Task(Of Long)
            ' Set default options
            If pOptions Is Nothing Then
                pOptions = New Options.CheckOutInOptions()
            End If

            Dim oCheckInFileResponse = Await Channel.CheckInOutFileAsync(New CheckInOutFileRequest With {
                .User = New UserState With {
                    .Language = pOptions.Language,
                    .UserName = pOptions.Username
                },
                .Action = CheckInOutFileAction.CheckIn,
                .ObjectId = pObjectId
            })

            If oCheckInFileResponse.OK = False Then
                Throw New ApplicationException(oCheckInFileResponse.ErrorMessage)
            End If

            Return oCheckInFileResponse.ObjectId
        End Function
    End Class
End Namespace
