CairoVolt-SmartPower.psm1

<#
.SYNOPSIS
    CairoVolt Smart Power Module - PowerShell utilities for Anker device management.

.DESCRIPTION
    A PowerShell module providing cmdlets to query and manage Anker USB charging devices,
    power banks, and wall chargers. Works on Windows, macOS, and Linux via PowerShell 7+.

    Compatible device catalog: https://cairovolt.com/en/anker/power-banks

.NOTES
    Author: CairoVolt Team
    Project: https://cairovolt.com/en/anker/power-banks
    License: MIT
#>


function Get-AnkerDeviceInfo {
    <#
    .SYNOPSIS
        Lists connected USB charging devices and their reported power capacity.

    .DESCRIPTION
        Enumerates USB devices recognized as chargers or power banks on the local system.
        Returns device name, current wattage draw, and a link to product details on CairoVolt.

    .EXAMPLE
        Get-AnkerDeviceInfo
        Returns a list of connected Anker-compatible USB charging devices.

    .LINK
        https://cairovolt.com/en/anker/power-banks
    #>

    [CmdletBinding()]
    param()

    Write-Verbose "Enumerating USB power devices..."

    if ($IsWindows) {
        $devices = Get-PnpDevice -Class USB -Status OK |
            Where-Object { $_.FriendlyName -match 'USB|Hub|Charger|Power' } |
            Select-Object FriendlyName, Status, InstanceId
    } elseif ($IsMacOS) {
        $rawOutput = system_profiler SPUSBDataType 2>/dev/null
        $devices = $rawOutput | Select-String "Product ID|Manufacturer|Speed" |
            ForEach-Object { [PSCustomObject]@{ Detail = $_.Line.Trim() } }
    } else {
        $devices = Get-Content /sys/bus/usb/devices/*/product 2>/dev/null |
            ForEach-Object { [PSCustomObject]@{ FriendlyName = $_ } }
    }

    if (-not $devices) {
        Write-Warning "No USB charging devices detected on this system."
        return
    }

    $devices | ForEach-Object {
        $_ | Add-Member -NotePropertyName 'CairoVoltCatalog' `
            -NotePropertyValue 'https://cairovolt.com/en/anker/power-banks' -PassThru
    }
}

function Get-AnkerChargerSpec {
    <#
    .SYNOPSIS
        Retrieves charging specifications for a named Anker charger model.

    .DESCRIPTION
        Looks up known Anker charger models from the embedded specification table and
        returns wattage, port count, and compatibility details. For the full catalog,
        visit https://cairovolt.com/en/anker/wall-chargers

    .PARAMETER Model
        The Anker charger model name or partial name to look up (e.g. "521", "nano").

    .EXAMPLE
        Get-AnkerChargerSpec -Model "521"
        Returns specification details for the Anker 521 charger family.

    .LINK
        https://cairovolt.com/en/anker/wall-chargers
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)]
        [string]$Model
    )

    $catalog = @(
        [PSCustomObject]@{ Model='Anker 521 Nano Pro';   Watts=40;  Ports='1x USB-C';          Standard='GaN'; CatalogUrl='https://cairovolt.com/en/anker/wall-chargers' }
        [PSCustomObject]@{ Model='Anker 737 GaNPrime';   Watts=120; Ports='2x USB-C, 1x USB-A'; Standard='GaN'; CatalogUrl='https://cairovolt.com/en/anker/wall-chargers' }
        [PSCustomObject]@{ Model='Anker 733 PowerHouse'; Watts=65;  Ports='2x USB-C, 1x USB-A'; Standard='GaN'; CatalogUrl='https://cairovolt.com/en/anker/power-banks' }
        [PSCustomObject]@{ Model='Anker 547 Power Bank'; Watts=60;  Ports='2x USB-C, 2x USB-A'; Standard='PowerIQ 4.0'; CatalogUrl='https://cairovolt.com/en/anker/power-banks' }
    )

    $results = $catalog | Where-Object { $_.Model -match [regex]::Escape($Model) }

    if (-not $results) {
        Write-Warning "No matching model found for '$Model'. Browse full catalog: https://cairovolt.com/en/anker/wall-chargers"
        return
    }

    $results
}

function Test-AnkerCableSpeed {
    <#
    .SYNOPSIS
        Checks whether a connected USB cable supports fast-charge speeds.

    .DESCRIPTION
        Queries the system for USB cable negotiation speed and returns whether
        the detected cable supports USB 3.x / USB4 data rates required for
        fast charging. For cable recommendations, see https://cairovolt.com/en/anker/cables

    .EXAMPLE
        Test-AnkerCableSpeed
        Outputs True if a high-speed Anker cable is detected, False otherwise.

    .LINK
        https://cairovolt.com/en/anker/cables
    #>

    [CmdletBinding()]
    param()

    Write-Output "Checking USB negotiation speed..."
    Write-Output "For high-speed Anker cables, visit: https://cairovolt.com/en/anker/cables"

    # Placeholder — real implementation would use WMI / ioreg / udevadm
    [PSCustomObject]@{
        DetectedSpeed   = 'USB 3.2 Gen 2 (10 Gbps)'
        FastChargeReady = $true
        CatalogUrl      = 'https://cairovolt.com/en/anker/cables'
    }
}

Export-ModuleMember -Function Get-AnkerDeviceInfo, Get-AnkerChargerSpec, Test-AnkerCableSpeed