Public/ConnectedSystems/Get-JIMConnectedSystemDeletionPreview.ps1

# Copyright (c) Tetron Limited. All rights reserved.
# Licensed under the Tetron Commercial License. See LICENSE file in the project root.

function Get-JIMConnectedSystemDeletionPreview {
    <#
    .SYNOPSIS
        Gets what deleting a Connected System would affect.
 
    .DESCRIPTION
        Retrieves a detailed impact analysis of what would be affected if the connected system were deleted.
        This includes counts of objects, Synchronisation Rules, run profiles, partitions, and metaverse objects that
        would be impacted. Use this before Remove-JIMConnectedSystem to understand the scope of the operation.
 
    .PARAMETER ConnectedSystemId
        The ID of the Connected System.
 
    .OUTPUTS
        What deleting the Connected System would remove, disconnect and recall.
 
    .EXAMPLE
        Get-JIMConnectedSystemDeletionPreview -ConnectedSystemId 1
 
        Gets the deletion impact preview for Connected System 1.
 
    .EXAMPLE
        $preview = Get-JIMConnectedSystemDeletionPreview -ConnectedSystemId 1
        if ($preview.warnings.Count -gt 0) { $preview.warnings | ForEach-Object { Write-Warning $_ } }
 
        Gets the deletion impact preview for Connected System 1 and displays any warnings.
 
    .LINK
        Remove-JIMConnectedSystem
        Get-JIMConnectedSystem
    #>

    [CmdletBinding()]
    [OutputType('JIM.ConnectedSystemDeletionPreview')]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [Alias('Id')]
        [int]$ConnectedSystemId
    )

    process {
        # Check connection first
        if (-not $script:JIMConnection) {
            Write-Error "You are not connected to JIM. Run Connect-JIM -Url <your JIM URL> to authenticate, then try again."
            return
        }

        Write-Verbose "Getting deletion preview for Connected System: $ConnectedSystemId"

        try {
            $result = Invoke-JIMApi -Endpoint "/api/v1/synchronisation/connected-systems/$ConnectedSystemId/deletion-preview"
            $result
        }
        catch {
            Write-Error "Failed to get deletion preview: $_"
        }
    }
}