Public/New-PCOciFixture.ps1

function New-PCOciFixture {
    <#
    .SYNOPSIS
        Writes a forged tenancy snapshot from a seed. Nothing in it is real.

    .DESCRIPTION
        The forge builds compartments, instances, volumes, backups, backup policies, plugin states and Cloud Guard
        problems in the shape of a real estate, with every id in the realm 'forge', every name starting 'FORGE-'
        and a 'forgedBy' stamp in the file. The same seed produces the same snapshot on every operating system.
        A run report is written beside the snapshot.

    .PARAMETER Path
        The folder to write into. Default: .\forge under the current location.

    .PARAMETER Seed
        The seed. Default 42.

    .PARAMETER Instances
        How many instances to forge. Default 24.

    .PARAMETER Days
        How many days of forged daily cost to write beside the snapshot. Default 30.

    .PARAMETER Deterministic
        Omit the generation time from the snapshot and the report, so two runs are byte-identical.

    .PARAMETER Force
        Overwrite an existing snapshot in the folder.

    .EXAMPLE
        New-PCOciFixture -Path .\forge -Seed 7 -Deterministic -Force
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([pscustomobject])]
    param(
        [string]$Path = (Join-Path (Get-Location).Path 'forge'),
        [int]$Seed = 42,
        [ValidateRange(1, 5000)][int]$Instances = 24,
        [ValidateRange(1, 366)][int]$Days = 30,
        [switch]$Deterministic,
        [switch]$Force
    )

    $snapshotPath = Join-Path $Path 'snapshot.json'
    $reportPath = Join-Path $Path 'snapshot.report.json'
    $usagePath = Join-Path $Path 'usage.json'
    $usageReportPath = Join-Path $Path 'usage.report.json'
    if ((Test-Path -LiteralPath $snapshotPath) -and -not $Force) {
        throw "A snapshot already exists at '$snapshotPath'. Use -Force to overwrite it."
    }
    if (-not $PSCmdlet.ShouldProcess($snapshotPath, "Write a forged snapshot (seed $Seed)")) { return }

    $options = [PowerCraft.OCI.Core.Forge.SnapshotForge+Options]::new()
    $options.Instances = $Instances
    $started = [DateTimeOffset]::UtcNow
    $snapshot = [PowerCraft.OCI.Core.Forge.SnapshotForge]::Build($Seed, $options)
    [PowerCraft.OCI.Core.Snapshot.SnapshotWriter]::Write($snapshot, $snapshotPath, [bool]$Deterministic)

    $report = [PowerCraft.OCI.Core.Report.RunReport]::ForSnapshot('New-PCOciFixture', $snapshot)
    $report.StartedAt = $started
    $report.DurationMs = [long]([DateTimeOffset]::UtcNow - $started).TotalMilliseconds
    $report.IdentitySource = 'forge'
    $report.Parameters['seed'] = [string]$Seed
    $report.Parameters['instances'] = [string]$Instances
    $report.Write($reportPath, [bool]$Deterministic)

    $usage = [PowerCraft.OCI.Core.Forge.UsageForge]::Build($snapshot, $Days, [DateTimeOffset]::new(2026, 11, 1, 0, 0, 0, [TimeSpan]::Zero))
    [PowerCraft.OCI.Core.Usage.UsageWriter]::Write($usage, $usagePath, [bool]$Deterministic)
    $usageReport = [PowerCraft.OCI.Core.Report.RunReport]::ForUsage('New-PCOciFixture', $usage)
    $usageReport.StartedAt = $started
    $usageReport.IdentitySource = 'forge'
    $usageReport.Parameters['seed'] = [string]$Seed
    $usageReport.Parameters['days'] = [string]$Days
    $usageReport.Write($usageReportPath, [bool]$Deterministic)

    [pscustomobject]@{
        SnapshotPath = (Resolve-Path -LiteralPath $snapshotPath).Path
        ReportPath   = (Resolve-Path -LiteralPath $reportPath).Path
        Seed         = $Seed
        Instances    = $snapshot.Instances.Count
        Volumes      = $snapshot.Volumes.Count
        Backups      = $snapshot.Backups.Count
        UsagePath    = (Resolve-Path -LiteralPath $usagePath).Path
        UsageRows    = $usage.Rows.Count
        ForgedBy     = $snapshot.ForgedBy
    }
}