Functions/GenXdev.AI/Remove-Face.ps1

################################################################################
<#
.SYNOPSIS
    Deletes a registered face by its identifier.
 
.DESCRIPTION
    This function deletes a face from the face recognition system using its
    unique identifier. It communicates with the API endpoint to remove the
    registered face data.
 
.PARAMETER Identifier
    The identifier of the face to delete.
 
.EXAMPLE
    Remove-Face -Identifier "JohnDoe"
 
    Deletes the face with identifier "JohnDoe" from the face recognition
    system.
#>


function Remove-Face {


    [CmdletBinding()]
    [Alias("rface")]

    param(
        ########################################################################
        [Parameter(
            Position = 0,
            Mandatory = $true,
            HelpMessage = "The identifier of the face to delete",
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateNotNullOrEmpty()]
        [string]$Identifier
        ########################################################################
    )

    begin {

        # define the api base url for the face recognition service
        $script:ApiBaseUrl = "http://127.0.0.1:8080"

        # ensure the face recognition service is running
        Microsoft.PowerShell.Utility\Write-Verbose "Ensuring face recognition service is available"
        GenXdev.AI\EnsureFaceRecognition
    }

    process {

        try {
            # construct the uri for the delete request with the face identifier
            $uri = "$($script:ApiBaseUrl)/faces?id=$Identifier"

            # send delete request to the api endpoint
            Microsoft.PowerShell.Utility\Write-Verbose ("Sending delete request to $uri")
            $response = Microsoft.PowerShell.Utility\Invoke-RestMethod `
                -Uri $uri `
                -Method Delete

            # inform user of successful deletion
            Microsoft.PowerShell.Utility\Write-Output (
                "Face deleted successfully for $Identifier"
            )

            return $response
        }
        catch {
            # report error if deletion fails
            Microsoft.PowerShell.Utility\Write-Error "Failed to delete face: $_"
        }
    }

    end {
    }
}
################################################################################