public/Set-UnraidNotification.ps1

function Set-UnraidNotification {
    <#
    .SYNOPSIS
        Updates notification status.

    .PARAMETER InputObject
        Notification or ID to update (accepts pipeline).

    .PARAMETER State
        New state: Archived or Unread.

    .PARAMETER Session
        Unraid session (defaults to current session).

    .EXAMPLE
        Get-UnraidNotification -Type unread | Set-UnraidNotification -State Archived
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType('void')]
    param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [object[]]$InputObject,

        [Parameter(Mandatory)]
        [ValidateSet('Archived', 'Unread')]
        [string]$State,

        [Parameter()]
        [UnraidSession]$Session = $script:DefaultUnraidSession
    )

    process {
        foreach ($item in $InputObject) {
            if ($item -is [UnraidNotification]) {
                $notificationId = $item.Id
                $currentType    = $item.Type
            }
            else {
                $notificationId = $item
                $currentType    = $null
            }

            if (!$notificationId) { continue }

            if ($State -eq 'Archived') {
                $mutationName = "archiveNotification"
                $targetType   = "ARCHIVE"
                $action       = "Archive Notification"
            }
            else {
                $mutationName = "unreadNotification"
                $targetType   = "UNREAD"
                $action       = "Mark as Unread"
            }

            if ($currentType -eq $targetType) {
                Write-Verbose "Notification '$notificationId' is already in $State state."
                Write-Output $item
                continue
            }

            if ($PSCmdlet.ShouldProcess($notificationId, $action)) {
                $gqlQuery = "mutation { $mutationName(id: `"$notificationId`") { id } }"

                Invoke-UnraidQuery -Query $gqlQuery -Session $Session -ErrorAction Stop | Out-Null

                if ($item -is [UnraidNotification]) {
                    $item.Type = $targetType
                    Write-Output $item
                }
            }
        }
    }
}