// engine/execution-plan/desktop-distribution.ts — SPEC-014b
// Distribution phase generator for desktop release specs (Electron, Tauri, .NET).
// SRP: single responsibility — desktop app release pipeline steps.
/**
 * Returns true if the spec is a desktop release spec (based on tags, title, or type).
 */
export function isDesktopReleaseSpec(spec) {
    const lower = `${spec.title} ${spec.tags.join(' ')}`.toLowerCase();
    return (lower.includes('release') ||
        lower.includes('distribut') ||
        lower.includes('publish') ||
        lower.includes('electron') ||
        lower.includes('tauri') ||
        lower.includes('dotnet') ||
        spec.type === 'infra');
}
/**
 * Generates a Distribution phase for desktop release specs.
 * Steps: platform build → code signing → packaging → smoke test installer → distribution.
 */
export function generateDesktopDistributionPhase(spec, startOrder) {
    const steps = [];
    let order = startOrder;
    const lower = `${spec.title} ${spec.tags.join(' ')}`.toLowerCase();
    const isElectron = lower.includes('electron');
    const isTauri = lower.includes('tauri');
    const isDotNet = lower.includes('dotnet') || lower.includes('.net');
    // Step 1: Platform-specific build
    steps.push({
        order: order++,
        title: 'Platform build (all target platforms)',
        description: buildPlatformDescription(isElectron, isTauri, isDotNet),
        files: buildPlatformFiles(isElectron, isTauri, isDotNet),
        dependsOn: [],
        verification: 'Build artifacts exist for each target platform. No compilation errors. App launches in sandboxed environment.',
        estimatedMinutes: 30,
        canRollback: false,
    });
    // Step 2: Code signing
    steps.push({
        order: order++,
        title: 'Code signing',
        description: buildSigningDescription(isElectron, isTauri),
        files: ['scripts/sign.sh', 'electron-builder.yml'],
        dependsOn: [],
        verification: 'Windows: `signtool verify` passes. macOS: `codesign -dv --verbose` shows Developer ID. Linux: checksums generated.',
        estimatedMinutes: 20,
        canRollback: false,
    });
    // Step 3: Packaging per platform
    steps.push({
        order: order++,
        title: 'Package installers per platform',
        description: buildPackagingDescription(isElectron, isTauri, isDotNet),
        files: buildPackagingFiles(isElectron, isTauri, isDotNet),
        dependsOn: [],
        verification: 'Windows: .exe or .msi installer created. macOS: .dmg file created. Linux: .AppImage or .deb created.',
        estimatedMinutes: 20,
        canRollback: false,
    });
    // Step 4: Smoke test installer
    steps.push({
        order: order++,
        title: 'Smoke test installer on clean machine',
        description: 'Install from the generated installer on a clean VM/machine (not dev machine). ' +
            'Verify: app installs without errors, launches correctly, core features work, ' +
            'uninstaller cleanly removes the app.',
        files: [],
        dependsOn: [],
        verification: 'App installs and launches on clean machine. Core user flow completes. ' +
            'Uninstall leaves no leftover files. No antivirus false positives.',
        estimatedMinutes: 40,
        canRollback: true,
    });
    // Step 5: Distribution
    steps.push({
        order: order,
        title: 'Distribute via target channel',
        description: buildDistributionDescription(isElectron, isTauri, isDotNet),
        files: [],
        dependsOn: [],
        verification: 'Channel confirms receipt. Update server (if applicable) serves new version. ' +
            'Auto-updater picks up new version within configured interval.',
        estimatedMinutes: 30,
        canRollback: true,
    });
    return steps;
}
function buildPlatformDescription(isElectron, isTauri, isDotNet) {
    if (isElectron) {
        return ('Run `electron-builder --win --mac --linux` (or Electron Forge). ' +
            'Targets: NSIS/Squirrel for Windows, DMG for macOS, AppImage/deb/snap for Linux. ' +
            'Ensure production environment variables are set.');
    }
    if (isTauri) {
        return ('Run `cargo tauri build` for each target platform. ' +
            'Targets: MSI/NSIS for Windows, DMG for macOS, AppImage/deb/rpm for Linux. ' +
            'Verify Tauri version and permissions in tauri.conf.json.');
    }
    if (isDotNet) {
        return ('Run `dotnet publish -c Release` with platform RID (win-x64, osx-x64, linux-x64). ' +
            'For MAUI: `dotnet publish -f net9.0-windows10.0.19041.0`. ' +
            'For WPF/WinForms: publish with ClickOnce or MSIX packaging.');
    }
    return 'Build release artifacts for all target platforms with production configuration.';
}
function buildPlatformFiles(isElectron, isTauri, isDotNet) {
    if (isElectron) {
        return ['electron-builder.yml', 'package.json', '.env.production'];
    }
    if (isTauri) {
        return ['src-tauri/tauri.conf.json', 'src-tauri/Cargo.toml', '.github/workflows/release.yml'];
    }
    if (isDotNet) {
        return ['*.csproj', 'publish.ps1', '.github/workflows/release.yml'];
    }
    return ['package.json', 'scripts/build-release.sh'];
}
function buildSigningDescription(isElectron, isTauri) {
    if (isElectron || isTauri) {
        return ('Windows: sign .exe/.msi with Authenticode certificate (EV cert recommended for SmartScreen). ' +
            'macOS: sign with Developer ID Application certificate, then notarize with Apple servers ' +
            '(`xcrun notarytool submit`). ' +
            'Linux: generate SHA256 checksums for AppImage/deb.');
    }
    return ('Sign build artifacts with platform code signing certificates. ' +
        'macOS: notarize for Gatekeeper compliance. Windows: Authenticode signing.');
}
function buildPackagingDescription(isElectron, isTauri, isDotNet) {
    if (isElectron) {
        return ('Electron Builder auto-generates installers. ' +
            'Verify: NSIS installer for Windows (with UAC elevation option), ' +
            'DMG with drag-to-Applications for macOS, ' +
            'AppImage for universal Linux (chmod +x required).');
    }
    if (isTauri) {
        return ('Tauri bundler generates native installers. ' +
            'Verify: MSI/NSIS for Windows, DMG for macOS (with notarization stapled), ' +
            'AppImage/deb/rpm for Linux.');
    }
    if (isDotNet) {
        return ('Package based on deployment target: ' +
            'ClickOnce for intranet deployment (requires .NET trust), ' +
            'MSIX for Microsoft Store or enterprise (requires Partner Center), ' +
            'WiX Toolset for custom MSI (most flexible).');
    }
    return 'Package release artifacts into platform-native installers.';
}
function buildPackagingFiles(isElectron, isTauri, isDotNet) {
    if (isElectron) {
        return ['electron-builder.yml', 'build/installer.nsh'];
    }
    if (isTauri) {
        return ['src-tauri/tauri.conf.json'];
    }
    if (isDotNet) {
        return ['*.wixproj', '*.wxs', '*.msixmanifest', 'publish/*.pubxml'];
    }
    return ['scripts/package.sh'];
}
function buildDistributionDescription(isElectron, isTauri, isDotNet) {
    if (isElectron) {
        return ('Upload artifacts to distribution channel: ' +
            'GitHub Releases (public), S3/CDN (direct download), or Microsoft Store. ' +
            'Update auto-update server (electron-updater RELEASES file or Squirrel.Windows endpoint). ' +
            'Send release announcement.');
    }
    if (isTauri) {
        return ('Upload artifacts to distribution channel. ' +
            'Update Tauri updater JSON endpoint with new version, download URLs, and signature. ' +
            'GitHub Releases or custom update server supported. ' +
            'Verify updater config in tauri.conf.json points to new endpoint.');
    }
    if (isDotNet) {
        return ('Deploy via configured channel: ' +
            'ClickOnce: publish to IIS/file share, update .application manifest. ' +
            'MSIX: submit to Partner Center or sideload via MDM policy. ' +
            'MSI: upload to software distribution system.');
    }
    return 'Distribute release artifacts via configured channels (Store, direct download, enterprise).';
}
//# sourceMappingURL=desktop-distribution.js.map