import { setupManifest } from '@start9labs/start-sdk'
import { alertInstall, alertUpdate, long, short } from './i18n'

/**
 * Proof of Work (proof-of-work) — StartOS 0.4 manifest.
 *
 * Contract invariants that MUST stay stable across all future releases so the
 * 0.3.5 \u2192 0.4 data migration and subsequent upgrades remain safe:
 *   - package identifier = 'proof-of-work' (matches the 0.3.5 package)
 *   - volume name        = 'main'        (matches the 0.3.5 volume)
 *   - mount path         = '/data'       (matches the 0.3.5 mount)
 *
 * NOTE: do NOT write the literal two-character token "i"+"d" followed by ":"
 * anywhere else in this file. s9pk.mk extracts PACKAGE_ID with a naive awk
 * that matches on that substring and will concatenate multiple hits into a
 * broken BASE_NAME (symptom: make warning "overriding commands for target
 * 'proof-of-work'" and "No rule to make target .git/HEAD").
 */
export const manifest = setupManifest({
  id: 'proof-of-work',
  title: 'Proof of Work',
  license: 'Proprietary',
  packageRepo: 'https://github.com/keysat-xyz/proof-of-work',
  upstreamRepo: 'https://github.com/keysat-xyz/proof-of-work',
  marketingUrl: 'https://github.com/keysat-xyz/proof-of-work',
  donationUrl: null,
  docsUrls: ['https://docs.start9.com/packaging/0.4.0.x/'],
  description: { short, long },
  volumes: ['main'],
  images: {
    main: {
      source: {
        dockerBuild: {
          // Both `workdir` and `dockerfile` are resolved by start-cli
          // relative to the PACKAGE directory (where this manifest
          // lives), per the 0.4.0.x packaging docs. That means:
          //   workdir: '../..'       -> Docker build context = repo root
          //                             (two levels up from
          //                             start9/0.4/). The
          //                             Dockerfile's COPY paths such as
          //                             'proof-of-work/...' and
          //                             'start9/0.4/...' are
          //                             resolved from there.
          //   dockerfile: './Dockerfile'
          //                          -> <package-dir>/Dockerfile. That's
          //                             where ours actually lives; the
          //                             Dockerfile sitting OUTSIDE the
          //                             workdir is fine -- Docker
          //                             supports it via `-f <path>
          //                             <context>` and buildkit resolves
          //                             COPY paths against the context
          //                             (workdir), not the Dockerfile's
          //                             directory.
          // DO NOT set dockerfile to './start9/0.4/Dockerfile'.
          // That would resolve to
          // start9/0.4/start9/0.4/Dockerfile
          // (nonexistent), producing
          // `resolve : lstat start9: no such file or directory`
          // from buildkit before any layer runs.
          workdir: '../..',
          dockerfile: './Dockerfile',
        },
      },
      // 0.4 beta is x86_64-only; expand to ['x86_64', 'aarch64'] post-beta.
      arch: ['x86_64'],
    },
  },
  alerts: {
    install: alertInstall,
    update: alertUpdate,
    uninstall: null,
    restore: null,
    start: null,
    stop: null,
  },
  dependencies: {},
})
