Classes/Public/TMActionRequest.ps1


class TMActionRequest {

    #region Non-Static Properties

    [String]$Type = 'ActionRequest'
    [PSCustomObject]$Params = [PSCustomObject]::new()
    [TMActionRequestOptions]$Options = [TMActionRequestOptions]::new()
    [Object]$Headers
    [Object]$Config
    [TMTask]$Task = [TMTask]::new()
    [Boolean]$Debug = $false
    [TMUserAccount]$UserAccount = [TMUserAccount]::new()
    [TMActionRequestParameter[]]$Parameters = @()
    [String]$PublicRSAKey
    [String]$LogPath
    [TMActionRequestUserSession]$TMUserSession = [TMActionRequestUserSession]::new()

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequest() {}

    TMActionRequest([Object]$object) {
        $this.Type = 'ActionRequest'
        $this.Params = $object.params
        $this.Options = [TMActionRequestOptions]::new($object.options)
        $this.Headers = $object.headers
        $this.Config = $object.config
        $this.Task = [TMTask]::new($object.task)
        $this.Debug = $object.debug
        $this.UserAccount = [TMUserAccount]::new($object.userAccount)
        if ($object.parameters) {
            $this.Parameters = $object.parameters | ForEach-Object { [TMActionRequestParameter]::new($_) }
        }
        $this.PublicRSAKey = $object.publicRSAKey
        $this.LogPath = $object.logPath
        $this.TMUserSession = [TMActionRequestUserSession]::new($object.tmUserSession)
    }

    #endregion Constructors

}


class TMActionRequestOptions {

    #region Non-Static Properties

    [Int64]$ActionId
    [Int64]$ProjectId
    [Object]$Credentials
    [TMActionRequestApiAction]$ApiAction
    [TMActionRequestCallback]$Callback

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestOptions() {}

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
    TMActionRequestOptions([Int64]$actionId, [Int64]$projectId, [Object]$credentials, [TMActionRequestApiAction]$apiAction, [TMActionRequestCallback]$callback) {
        $this.ActionId = $actionId
        $this.ProjectId = $projectId
        $this.Credentials = $credentials
        $this.ApiAction = [TMActionRequestApiAction]::new($apiAction)
        $this.Callback = [TMActionRequestCallback]::new($callback)
    }

    TMActionRequestOptions([Object]$object) {
        $this.ActionId = $object.actionId
        $this.ProjectId = $object.projectId
        $this.Credentials = $object.credentials
        $this.ApiAction = [TMActionRequestApiAction]::new($object.apiAction)
        $this.Callback = [TMActionRequestCallback]::new($object.callback)
    }

    #endregion Constructors

}


class TMActionRequestApiAction {

    #region Non-Static Properties

    [Int64]$Id
    [String]$Name
    [Int64]$Version
    [String]$DictionaryMethodName
    [String]$ConnectorMethod
    [Int64]$UseWithTask
    [Int64]$ReactionScriptsValid
    [String]$DocUrl
    [Boolean]$IsRemote = $false
    [Int64]$UseWithAsset
    [String]$Description
    [String]$EndpointUrl
    [TMTaskActionType]$ActionType = [TMTaskActionType]::new()
    [TMReference]$Provider = [TMReference]::new()
    [TMReference]$Project = [TMReference]::new()
    [Nullable[DateTime]]$DateCreated
    [Nullable[DateTime]]$LastUpdated
    [Int64]$Timeout
    [String]$HttpMethod
    [TMTaskActionMethodParam[]]$MethodParams = @()
    [String]$Script
    [String]$ReactionScripts
    [Boolean]$DebugEnabled

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestApiAction() {}

    TMActionRequestApiAction([Object]$object) {
        $this.Id = $object.id
        $this.Name = $object.name
        $this.Version = $object.version
        $this.DictionaryMethodName = $object.dictionaryMethodName
        $this.ConnectorMethod = $object.connectorMethod
        $this.UseWithTask = $object.useWithTask
        $this.ReactionScriptsValid = $object.reactionScriptsValid
        $this.DocUrl = $object.docUrl
        $this.IsRemote = $object.isRemote
        $this.UseWithAsset = $object.useWithAsset
        $this.Description = $object.description
        $this.EndpointUrl = $object.endpointUrl
        $this.ActionType = [TMTaskActionType]::new($object.actionType)
        $this.Provider = [TMReference]::new($object.provider)
        $this.Project = [TMReference]::new($object.project)
        $this.DateCreated = $object.dateCreated
        $this.LastUpdated = $object.lastUpdated
        $this.Timeout = $object.timeout
        $this.HttpMethod = $object.httpMethod
        if ($object.methodParams -is [System.String]) {
            $object.methodParams = ($object.methodParams | ConvertFrom-Json -Depth 5)
        }
        $this.MethodParams = $object.methodParams | ForEach-Object { [TMTaskActionMethodParam]::new($_) }
        $this.Script = $object.script
        $this.ReactionScripts = $object.reactionScripts
        $this.DebugEnabled = $object.debugEnabled
    }

    #endregion Constructors

}


class TMActionRequestCallback {

    #region Non-Static Properties

    [String]$SiteUrl
    [String]$Token
    [String]$RefreshToken
    [Int64]$ExpirationSeconds
    [Int64]$GrantedDate

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestCallback() {}

    TMActionRequestCallback([String]$siteUrl, [String]$token, [String]$refreshToken, [Int64]$expirationSeconds, [Int64]$grantedDate) {
        $this.SiteUrl = $siteUrl
        $this.Token = $token
        $this.RefreshToken = $refreshToken
        $this.ExpirationSeconds = $expirationSeconds
        $this.GrantedDate = $grantedDate
    }

    TMActionRequestCallback([Object]$object) {
        $this.SiteUrl = $object.siteUrl
        $this.Token = $object.token
        $this.RefreshToken = $object.refreshToken
        $this.ExpirationSeconds = $object.expirationSeconds
        $this.GrantedDate = $object.grantedDate
    }

    #endregion Constructors

}


class TMActionRequestParameter {

    #region Non-Static Properties

    [String]$Name
    [String]$Type
    [Boolean]$CanCache = $true
    [String]$Description

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestParameter() {}

    TMActionRequestParameter([String]$name, [String]$type, [Boolean]$canCache, [String]$description) {
        $this.Name = $name
        $this.Type = $type
        $this.CanCache = $canCache
        $this.Description = $description
    }

    TMActionRequestParameter([Object]$object) {
        $this.Name = $object.name
        $this.Type = $object.type
        $this.CanCache = $object.canCache
        $this.Description = $object.description
    }

    #endregion Constructors

}


class TMActionRequestUserSession {

    #region Non-Static Properties

    [String]$Url
    [String]$TmVersion
    [String]$Jsessionid
    [TMSessionUserContext]$UserContext = [TMSessionUserContext]::new()
    [TMActionRequestUserSessionCsrf]$Csrf = [TMActionRequestUserSessionCsrf]::new()
    [TMActionRequestUserSessionNotices]$Notices = [TMActionRequestUserSessionNotices]::new()
    [TMActionRequestUserSessionReporting]$Reporting = [TMActionRequestUserSessionReporting]::new()

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestUserSession() {}

    TMActionRequestUserSession([String]$url, [String]$tmVersion, [String]$jsessionid, [TMSessionUserContext]$userContext, [TMActionRequestUserSessionCsrf]$csrf, [TMActionRequestUserSessionNotices]$notices, [TMActionRequestUserSessionReporting]$reporting) {
        $this.Url = $url
        $this.TmVersion = $tmVersion
        $this.Jsessionid = $jsessionid
        $this.UserContext = [TMSessionUserContext]::new($userContext)
        $this.Csrf = [TMActionRequestUserSessionCsrf]::new($csrf)
        $this.Notices = [TMActionRequestUserSessionNotices]::new($notices)
        $this.Reporting = [TMActionRequestUserSessionReporting]::new($reporting)
    }

    TMActionRequestUserSession([Object]$object) {
        $this.Url = $object.url
        $this.TmVersion = $object.tmVersion
        $this.Jsessionid = $object.jsessionid
        $this.UserContext = [TMSessionUserContext]::new($object.userContext)
        $this.Csrf = [TMActionRequestUserSessionCsrf]::new($object.csrf)
        $this.Notices = [TMActionRequestUserSessionNotices]::new($object.notices)
        $this.Reporting = [TMActionRequestUserSessionReporting]::new($object.reporting)
    }

    #endregion Constructors

}


class TMActionRequestUserSessionCsrf {

    #region Non-Static Properties

    [String]$TokenHeaderName
    [String]$Token

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestUserSessionCsrf() {}

    TMActionRequestUserSessionCsrf([String]$tokenHeaderName, [String]$token) {
        $this.TokenHeaderName = $tokenHeaderName
        $this.Token = $token
    }

    TMActionRequestUserSessionCsrf([Object]$object) {
        $this.TokenHeaderName = $object.tokenHeaderName
        $this.Token = $object.token
    }

    #endregion Constructors

}


class TMActionRequestUserSessionNotices {

    #region Non-Static Properties

    [String[]]$NoticesList

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestUserSessionNotices() {}

    TMActionRequestUserSessionNotices([String[]]$noticesList) {
        $this.NoticesList = $noticesList
    }

    TMActionRequestUserSessionNotices([Object]$object) {
        $this.NoticesList = $object.noticesList
    }

    #endregion Constructors

}


class TMActionRequestUserSessionReporting {

    #region Non-Static Properties

    [Boolean]$Enabled
    [String]$TmApiUrl
    [String]$TmSsoUrl
    [String]$ReportWebUrl
    [String]$ReportApiUrl
    [String]$SsoToken

    #endregion Non-Static Properties

    #region Constructors

    TMActionRequestUserSessionReporting() {}

    TMActionRequestUserSessionReporting([Boolean]$enabled, [String]$tmApiUrl, [String]$tmSsoUrl, [String]$reportWebUrl, [String]$reportApiUrl, [String]$ssoToken) {
        $this.Enabled = $enabled
        $this.TmApiUrl = $tmApiUrl
        $this.TmSsoUrl = $tmSsoUrl
        $this.ReportWebUrl = $reportWebUrl
        $this.ReportApiUrl = $reportApiUrl
        $this.SsoToken = $ssoToken
    }

    TMActionRequestUserSessionReporting([Object]$object) {
        $this.Enabled = $object.enabled
        $this.TmApiUrl = $object.tmApiUrl
        $this.TmSsoUrl = $object.tmSsoUrl
        $this.ReportWebUrl = $object.reportWebUrl
        $this.ReportApiUrl = $object.reportApiUrl
        $this.SsoToken = $object.ssoToken
    }

    #endregion Constructors

}