// Copyright (c) 2026 defconxt. All rights reserved.
// Licensed under AGPL-3.0 — see LICENSE file for details.

/**
 * NERF Benchmark — Harness configuration.
 */

import { homedir } from 'node:os';
import { join } from 'node:path';
import { createHash } from 'node:crypto';

export const DEFAULT_CLONE_DIR = join(homedir(), '.nerf', 'benchmarks');
export const BENCHMARKS_SUBDIR = 'benchmarks';

export class HarnessConfig {
  constructor(opts = {}) {
    this.repoUrl = opts.repoUrl ?? '';
    this.cloneDir = opts.cloneDir ?? DEFAULT_CLONE_DIR;
    this.benchmarksSubdir = opts.benchmarksSubdir ?? BENCHMARKS_SUBDIR;
    this.dockerBuildTimeout = opts.dockerBuildTimeout ?? 300;
    this.dockerStartTimeout = opts.dockerStartTimeout ?? 120;
    this.dockerStopTimeout = opts.dockerStopTimeout ?? 30;
    this.noCache = opts.noCache ?? false;
    this.flagPrefix = opts.flagPrefix ?? 'FLAG';
  }

  get benchmarksDir() { return join(this.cloneDir, this.benchmarksSubdir); }

  generateFlag(benchmarkName) {
    const upper = benchmarkName.toUpperCase();
    const sha = createHash('sha256').update(upper).digest('hex');
    return `${this.flagPrefix}{${sha}}`;
  }
}
