Function Enable-User {
    <#
    .SYNOPSIS
        Enables a disabled user account in DRA.

    .DESCRIPTION
        Enables one or more disabled user accounts in the DRA environment.

    .PARAMETER UserName
        The name(s) of the user(s) to enable.

    .PARAMETER DraServer
        The FQDN of the DRA server. Defaults to "mcguire.dra.us.af.mil".

    .EXAMPLE
        Enable-User -UserName 'Doe.John', 'Smith.Jane'
        Enables the accounts for two users.

    .EXAMPLE
        'Doe.John' | Enable-User -Verbose
        Enables a user account passed via the pipeline and shows verbose output.
    #>
    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
        [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
        [string[]]$UserName,

        [Parameter(Position=1)]
        [string]$DraServer = "mcguire.dra.us.af.mil"
    )

    Begin {
        $UserName = @(Split-ToolArgumentList -Value $UserName)
        $ouPath = ",OU=McGuire AFB Users,OU=McGuire AFB,OU=AFCONUSWEST,OU=Bases,DC=AREA52,DC=AFNOAPPS,DC=USAF,DC=MIL"
        $i = 1
        $total = $UserName.Count
    }

    Process {
        foreach ($user in $UserName) {
            $percentComplete = ($i / $total) * 100
            Show-ProgressBar -Activity "Enabling $user" -PercentComplete $percentComplete

            $identifier = "cn=$user$ouPath"
            Write-Verbose "Attempting to enable user with identifier: $identifier"

            if ($pscmdlet.ShouldProcess($identifier, "Enable User Account")) {
                try {
                    if ($script:SimulationMode) {
                        Set-ToolADUserProperty -Identity $user -Property 'Enabled' -Value $true -ErrorAction Stop | Out-Null
                        Write-Verbose "Simulation: enabled user: $user"
                    } else {
                        Enable-DRAUser -ErrorAction Stop `
                            -Domain $env:USERDNSDOMAIN `
                            -DRARestServer $DraServer `
                            -DRARestPort 8755 `
                            -DRAHostServer $DraServer `
                            -DRAHostPort 11192 `
                            -Identifier $identifier `
                            -Force

                        Write-Verbose "Successfully enabled user: $user"
                    }
                }
                catch {
                    Write-Warning "Could not enable user '$user'. Error: $($_.Exception.Message)"
                }
            }
            $i++
        }
    }

    End {
        Show-ProgressBar -Activity "Operation Complete" -PercentComplete 100
    }
}
