VM-AutoTagger.psm1

#Requires -Version 5.1

<#
.SYNOPSIS
    VM-AutoTagger root module. Dot-sources all public and private functions.
.DESCRIPTION
    Automatically tag VMware vSphere and Microsoft Hyper-V VMs with OS, hardware tier,
    compliance status, and custom categories defined via YAML tag profiles. For vSphere,
    uses native tags via PowerCLI. For Hyper-V, stores tags as structured JSON in VM Notes.
    Supports compliance checking, stale VM detection, drift detection, and HTML dashboard reporting.
#>


# Dot-source private functions first, then public functions
$Private = @(Get-ChildItem -Path "$PSScriptRoot\Private\*.ps1" -ErrorAction SilentlyContinue)
$Public  = @(Get-ChildItem -Path "$PSScriptRoot\Public\*.ps1" -ErrorAction SilentlyContinue)

foreach ($import in @($Private + $Public)) {
    try {
        . $import.FullName
    }
    catch {
        Write-Error "Failed to import $($import.FullName): $_"
    }
}

# Initialize state directory for sync state, drift detection, etc.
$script:StateDir = Join-Path -Path $env:USERPROFILE -ChildPath '.vmautotagger'
if (-not (Test-Path $script:StateDir)) {
    New-Item -Path $script:StateDir -ItemType Directory -Force | Out-Null
}

# Reference the Profiles directory shipped with this module
$script:ProfileDir = Join-Path -Path $PSScriptRoot -ChildPath 'Profiles'

# Module-level default cost model for stale VM waste estimation
$script:DefaultCpuCostPerHour   = 0.05
$script:DefaultRamCostPerGBHour = 0.01