## Debug test for NIP manifest parsing

import std/[times, options]
import nip/nip_manifest
import nip/manifest_parser

# Create a simple manifest
let manifest = NIPManifest(
  name: "testapp",
  version: SemanticVersion(major: 1, minor: 2, patch: 3),
  buildDate: now(),
  metadata: AppInfo(
    description: "Test app",
    license: "MIT",
    tags: @["test", "example"]
  ),
  provenance: ProvenanceInfo(
    source: "https://example.com",
    sourceHash: "xxh3-123",
    buildTimestamp: now()
  ),
  buildConfig: BuildConfiguration(
    configureFlags: @["--enable-test"],
    compilerFlags: @["-O2"],
    compilerVersion: "gcc-13.0.0",
    targetArchitecture: "x86_64",
    libc: "musl",
    allocator: "jemalloc",
    buildSystem: "cmake"
  ),
  casChunks: @[
    ChunkReference(hash: "xxh3-chunk1", size: 1024, chunkType: Binary, path: "bin/app")
  ],
  desktop: DesktopMetadata(
    desktopFile: DesktopFileSpec(
      name: "Test App",
      exec: "/usr/bin/testapp",
      icon: "testapp",
      terminal: false,
      categories: @["Utility"],
      keywords: @["test"]
    ),
    icons: @[IconSpec(size: 48, path: "icons/test.png", format: "png")],
    mimeTypes: @["text/plain"],
    appId: "org.example.testapp"
  ),
  namespace: NamespaceConfig(
    namespaceType: "user",
    permissions: Permissions(
      network: true,
      gpu: false,
      audio: true,
      camera: false,
      microphone: false,
      filesystem: @[FilesystemAccess(path: "/home", mode: ReadOnly)],
      dbus: DBusAccess(session: @["org.freedesktop.Notifications"], system: @[], own: @[])
    ),
    mounts: @[Mount(source: "/host", target: "/app", mountType: Bind, readOnly: true)]
  ),
  buildHash: "xxh3-buildhash",
  signature: SignatureInfo(algorithm: "ed25519", keyId: "key-123", signature: "sig-456")
)

# Generate KDL
echo "=== Generated KDL ==="
let kdl = generateNIPManifest(manifest)
echo kdl
echo ""

# Parse it back
echo "=== Parsing KDL ==="
let parsed = parseNIPManifest(kdl)

# Compare fields
echo "=== Comparison ==="
echo "Name: ", manifest.name, " vs ", parsed.name, " - ", manifest.name == parsed.name
echo "Version: ", manifest.version, " vs ", parsed.version, " - ", manifest.version == parsed.version
echo "Description: ", manifest.metadata.description, " vs ", parsed.metadata.description, " - ", manifest.metadata.description == parsed.metadata.description
echo "License: ", manifest.metadata.license, " vs ", parsed.metadata.license, " - ", manifest.metadata.license == parsed.metadata.license
echo "Tags: ", manifest.metadata.tags, " vs ", parsed.metadata.tags, " - ", manifest.metadata.tags == parsed.metadata.tags
echo "Source: ", manifest.provenance.source, " vs ", parsed.provenance.source, " - ", manifest.provenance.source == parsed.provenance.source
echo "Build hash: ", manifest.buildHash, " vs ", parsed.buildHash, " - ", manifest.buildHash == parsed.buildHash
echo "App ID: ", manifest.desktop.appId, " vs ", parsed.desktop.appId, " - ", manifest.desktop.appId == parsed.desktop.appId
echo "Namespace type: ", manifest.namespace.namespaceType, " vs ", parsed.namespace.namespaceType, " - ", manifest.namespace.namespaceType == parsed.namespace.namespaceType
echo "Network perm: ", manifest.namespace.permissions.network, " vs ", parsed.namespace.permissions.network, " - ", manifest.namespace.permissions.network == parsed.namespace.permissions.network
echo "CAS chunks: ", manifest.casChunks.len, " vs ", parsed.casChunks.len, " - ", manifest.casChunks.len == parsed.casChunks.len
