Public/Remove-Earning.ps1

function Remove-Earning {
    <#
    .SYNOPSIS
        Removes an earning entry.
 
    .DESCRIPTION
        Deletes an earning from the data store by ID.
 
    .PARAMETER Id
        The ID of the earning to remove.
 
    .PARAMETER Budget
        Optional budget name to target. Uses active budget if not specified.
 
    .PARAMETER DataPath
        Optional custom path for data storage. Overrides budget-based paths.
 
    .EXAMPLE
        Remove-Earning -Id "abc123"
 
    .OUTPUTS
        None
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [string]$Id,

        [Parameter()]
        [string]$Budget,

        [Parameter()]
        [string]$DataPath
    )

    process {
        $resolvedPath = Resolve-DataPath -DataPath $DataPath -Budget $Budget
        if (-not $resolvedPath) { return }

        $earnings = Read-EntityData -EntityType 'Earning' -DataPath $resolvedPath
        $earning = $earnings | Where-Object { $_.Id -eq $Id }

        if (-not $earning) {
            Write-Error "Earning with ID '$Id' not found."
            return
        }

        if ($PSCmdlet.ShouldProcess($earning.Name, "Remove earning")) {
            $updatedEarnings = @($earnings | Where-Object { $_.Id -ne $Id })
            if (Write-EntityData -EntityType 'Earning' -Data $updatedEarnings -DataPath $resolvedPath) {
                Write-Verbose "Removed earning: $($earning.Name)"
            }
        }
    }
}