Public/Employees/Send-UKGEmployeeInvite.ps1

function Send-UKGEmployeeVaultInvite {
    <#
    .SYNOPSIS
        Sends an electronic vault invitation to an employee.

    .DESCRIPTION
        Invites an employee to access their electronic vault for secure document storage.

    .PARAMETER Id
        The unique identifier of the employee.

    .PARAMETER SendEmail
        Whether to send an email invitation to the employee.

    .EXAMPLE
        Send-UKGEmployeeVaultInvite -Id "emp123"

    .EXAMPLE
        Send-UKGEmployeeVaultInvite -Id "emp123" -SendEmail

    .OUTPUTS
        Response from the API confirming the invitation was sent.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [Alias('EmployeeId')]
        [string]$Id,

        [Parameter()]
        [switch]$SendEmail
    )

    process {
        if ($PSCmdlet.ShouldProcess($Id, 'Send Electronic Vault Invite')) {
            $body = @{}
            if ($SendEmail) {
                $body['send_email'] = $true
            }

            $response = Invoke-UKGRequest -Endpoint "/employees/$Id/electronic_vault_invite" -Method POST -Body $body
            return $response
        }
    }
}

function Send-UKGEmployeePortalInvite {
    <#
    .SYNOPSIS
        Sends a portal invitation to an employee.

    .DESCRIPTION
        Invites an employee to access the HR portal.

    .PARAMETER Id
        The unique identifier of the employee.

    .PARAMETER SendEmail
        Whether to send an email invitation to the employee.

    .EXAMPLE
        Send-UKGEmployeePortalInvite -Id "emp123"

    .EXAMPLE
        Get-UKGEmployee -All | Where-Object { -not $_.portal_active } | Send-UKGEmployeePortalInvite

    .OUTPUTS
        Response from the API confirming the invitation was sent.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [Alias('EmployeeId')]
        [string]$Id,

        [Parameter()]
        [switch]$SendEmail
    )

    process {
        if ($PSCmdlet.ShouldProcess($Id, 'Send Portal Invite')) {
            $body = @{}
            if ($SendEmail) {
                $body['send_email'] = $true
            }

            $response = Invoke-UKGRequest -Endpoint "/employees/$Id/portal_invite" -Method POST -Body $body
            return $response
        }
    }
}

function Remove-UKGEmployeeVaultLink {
    <#
    .SYNOPSIS
        Removes the electronic vault link for an employee.

    .DESCRIPTION
        Unlinks an employee from their electronic vault.

    .PARAMETER Id
        The unique identifier of the employee.

    .EXAMPLE
        Remove-UKGEmployeeVaultLink -Id "emp123"

    .OUTPUTS
        None on success.
    #>

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

    process {
        if ($PSCmdlet.ShouldProcess($Id, 'Remove Electronic Vault Link')) {
            Invoke-UKGRequest -Endpoint "/employees/$Id/electronic_vault_link" -Method DELETE
        }
    }
}

function Send-UKGEmployeeVaultDocument {
    <#
    .SYNOPSIS
        Sends a document to an employee's electronic vault.

    .DESCRIPTION
        Uploads a document directly to an employee's electronic vault.

    .PARAMETER Id
        The unique identifier of the employee.

    .PARAMETER FilePath
        Path to the document file to upload.

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

    .PARAMETER DocumentTypeId
        The ID of the document type.

    .PARAMETER Title
        Title for the document.

    .PARAMETER Description
        Description of the document.

    .EXAMPLE
        Send-UKGEmployeeVaultDocument -Id "emp123" -FilePath "C:\Docs\contract.pdf" -DocumentTypeId "dt001"

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

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [Alias('EmployeeId')]
        [string]$Id,

        [Parameter(Mandatory)]
        [ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
        [string]$FilePath,

        [Parameter()]
        [string]$FileName,

        [Parameter()]
        [string]$DocumentTypeId,

        [Parameter()]
        [string]$Title,

        [Parameter()]
        [string]$Description
    )

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

        if ($PSCmdlet.ShouldProcess("$actualFileName to employee $Id", 'Send Document to Vault')) {
            $body = @{}
            if ($DocumentTypeId) { $body['document_type_id'] = $DocumentTypeId }
            if ($Title) { $body['title'] = $Title }
            if ($Description) { $body['description'] = $Description }

            $response = Invoke-UKGRequest -Endpoint "/employees/$Id/electronic_vault_documents" -Method POST -FilePath $FilePath -FileName $FileName -Body $body
            return $response
        }
    }
}