Public/Documents/Send-UKGDocument.ps1

function Send-UKGDocument {
    <#
    .SYNOPSIS
        Uploads a document to the UKG HR Service Delivery system.

    .DESCRIPTION
        Uploads a document file to the system for processing and storage.

    .PARAMETER FilePath
        Path to the document file to upload.

    .PARAMETER FileName
        Name for the document (defaults to file basename).

    .PARAMETER DocumentTypeId
        The ID of the document type.

    .PARAMETER EmployeeId
        The ID of the employee to associate the document with.

    .PARAMETER Title
        Title for the document.

    .PARAMETER Description
        Description of the document.

    .PARAMETER Metadata
        Hashtable of additional metadata for the document.

    .EXAMPLE
        Send-UKGDocument -FilePath "C:\Docs\contract.pdf" -EmployeeId "emp123" -DocumentTypeId "dt001"

    .EXAMPLE
        Send-UKGDocument -FilePath "C:\Docs\policy.pdf" -Title "Company Policy 2024" -Description "Updated HR policies"

    .OUTPUTS
        Response from the API with document details.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)]
        [ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
        [string]$FilePath,

        [Parameter()]
        [string]$FileName,

        [Parameter()]
        [string]$DocumentTypeId,

        [Parameter()]
        [string]$EmployeeId,

        [Parameter()]
        [string]$Title,

        [Parameter()]
        [string]$Description,

        [Parameter()]
        [hashtable]$Metadata
    )

    $actualFileName = if ($FileName) { $FileName } else { [System.IO.Path]::GetFileName($FilePath) }

    if ($PSCmdlet.ShouldProcess($actualFileName, 'Upload Document')) {
        $body = @{}
        if ($DocumentTypeId) { $body['document_type_id'] = $DocumentTypeId }
        if ($EmployeeId) { $body['employee_id'] = $EmployeeId }
        if ($Title) { $body['title'] = $Title }
        if ($Description) { $body['description'] = $Description }

        if ($Metadata) {
            foreach ($key in $Metadata.Keys) {
                $body[$key] = $Metadata[$key]
            }
        }

        $response = Invoke-UKGRequest -Endpoint '/document' -Method POST -FilePath $FilePath -FileName $FileName -Body $body

        if ($response) {
            $response.PSObject.TypeNames.Insert(0, 'UKG.Document')
        }

        return $response
    }
}