

function Get-SectigoCertificateTypes {
    [CmdletBinding()]
    param (
        [string]$ApiToken=$env:SectigoToken
    )

    if (-Not $ApiToken) {
        $ApiToken=Read-Host "ApiToken:"
    }

	. $PSScriptRoot\..\Private\Set-Onload.ps1

    [string]$CertificateTypesUrl= $BaseAPIUrl + "/api/ssl/v1/types"
    Write-Verbose -Verbose "CertificateTypesUrl: $CertificateTypesUrl"

    # 1. Prepare the Authorization Header
    # The Sectigo API usually requires the token in a Bearer authorization header.
    $headers = @{
        "Authorization" = "Bearer $ApiToken"
        "Content-Type"  = "application/json"
    }

    # 2. Send the Request (GET is the standard method for listing resources)
    $response = Invoke-WebRequest -Uri $CertificateTypesUrl -Method Get -Headers $headers -UseBasicParsing

    if ($response.StatusCode -eq 200) {
        # 3. Process the Response
        $certTypes = $response.Content | ConvertFrom-Json

        # ASSUMPTION: The API returns an array of objects,
        # each representing a certificate type.
        # This function returns the entire list/array.
        return $certTypes

    } else {
        Write-Error "Failed to get Certificate Types. Status code: $($response.StatusCode)."
        Write-Error "Response content: $($response.Content)"
        return $null
    }
}