import unittest
import std/times
import ../src/nip/types

suite "Core Data Types":

  test "NpkManifest can be instantiated correctly":
    let manifest = NpkManifest(
      name: "htop",
      version: SemVer("3.3.0"),
      description: "Interactive process viewer",
      channels: @["stable"],
      source: NpkSource(originPackage: "htop", originVersion: "3.3.0-1"),
      dependencies: @[NpkDependency(name: "ncurses", hash: Blake2bHash("hash123"))],
      build: NpkBuild(
        timestamp: getTime(),
        buildSystem: "x86_64-linux",
        compiler: "gcc",
        envHash: Blake2bHash("envhash123")
      ),
      files: @[NpkFile(path: "/bin/htop", hash: Blake2bHash("filehash123"), permissions: "755")],
      artifacts: @[NpkArtifact(name: "license", hash: Blake2bHash("licensehash123"))],
      services: @[NpkService(serviceType: "systemd", name: "htop.service", hash: Blake2bHash("servicehash123"))],
      signatures: @[NpkSignature(keyType: "ed25519", keyId: "keyid123", value: "sig123")]
    )
    check(manifest.name == "htop")
    check(manifest.version == SemVer("3.3.0"))
    check(manifest.dependencies.len == 1)
    check(manifest.dependencies[0].name == "ncurses")

  test "NipLock can be instantiated correctly":
    let lockfile = NipLock(
      lockfileVersion: "1.2",
      generation: LockfileGeneration(
        id: Blake2bHash("genhash123"),
        created: getTime(),
        previous: Blake2bHash("prevgenhash123")
      ),
      packages: @[LockfilePackage(name: "htop", hash: Blake2bHash("htophash123"))]
    )
    check(lockfile.lockfileVersion == "1.2")
    check(lockfile.packages.len == 1)
    check(lockfile.packages[0].name == "htop")
