// h dev seed-harbor-cli
// deno run -A ./.scripts/seed-harbor-cli.ts

import * as path from "jsr:@std/path";
import { paths } from "../routines/paths.js";

interface ServiceConfig {
  handle: string;
  user?: string;
}

const SERVICES: ServiceConfig[] = [
  { handle: "opencode" },
  { handle: "hermes" },
  { handle: "openclaw", user: "node" },
];

function generate(svc: ServiceConfig): string {
  const userEnv = svc.user
    ? `\n      - HARBOR_CLI_USER=${svc.user}`
    : "";

  return `
# This file is generated by seed-harbor-cli.ts script,
# any updates will be overwritten.
services:
  ${svc.handle}:
    volumes:
      - \${HARBOR_HOME_VOLUME}:\${HARBOR_HOME_VOLUME}
      - /var/run/docker.sock:/var/run/docker.sock
      - ./shared/harbor_cli_init.sh:/harbor/harbor_cli_init.sh:ro
      - \${HARBOR_HOME_VOLUME}/skills/run-llms/SKILL.md:/harbor/SKILL.md:ro
    environment:
      - HARBOR_HOME=\${HARBOR_HOME_VOLUME}${userEnv}
`.trim() + "\n";
}

async function main() {
  for (const svc of SERVICES) {
    const outName = `compose.x.${svc.handle}.harbor-cli.yml`;
    const outPath = path.join(paths.services, outName);
    const content = generate(svc);
    console.log(`Writing ${outPath}...`);
    await Deno.writeTextFile(outPath, content);
  }

  console.log("Done!");
}

main().catch(console.error);
