/**
 * get-services — list running services on the target. Asset-self.
 *
 * Audit purpose: when a ticket resolves by restarting/fixing a specific
 * Windows service, the next tech should be able to find that service in
 * the IT Glue Configuration record's operating_system_notes. The audit
 * pipeline cross-references the service inventory with ticket history to
 * propose notes_promotions like "Add 'BartenderProcessService' to
 * operating_system_notes — referenced in T20260502.0033."
 */

import { type RmmScript, parseJsonOutput } from './types';

export const getServices: RmmScript = {
  id: 'get-services',
  name: 'Running services',
  description:
    'Snapshot of all running Windows services on the target — Name, DisplayName, StartType, ServiceType.',
  target_type: 'asset_self',
  expected_runtime_seconds: 15,
  version: 1,
  body: `
$ErrorActionPreference = 'Stop'
$services = Get-Service | Where-Object { $_.Status -eq 'Running' } |
  Select-Object Name, DisplayName, StartType, ServiceType
@{
  hostname = $env:COMPUTERNAME
  captured_at_utc = (Get-Date).ToUniversalTime().ToString("o")
  count = $services.Count
  services = $services
} | ConvertTo-Json -Depth 4 -Compress
`.trim(),
  parseOutput: (stdout) => parseJsonOutput(stdout),
};
