import path from "node:path";
import { exists } from "../fsx.ts";
import type { TargetAdapter, TargetContext } from "../types.ts";
import { anyExists, scopeRoot, skillDirActions } from "./common.ts";

/**
 * Claude Code — ~/.claude/skills/designpaca/ (전역) 또는 .claude/skills/designpaca/ (프로젝트).
 * SKILL.md 포맷을 그대로 쓰므로 변환이 없다.
 */
export const claudeCode: TargetAdapter = {
  id: "claude-code",
  label: "Claude Code",
  hint: "~/.claude/skills/designpaca — SKILL.md 그대로",
  scopes: ["user", "project"],

  async detect(ctx: TargetContext) {
    return anyExists([
      path.join(ctx.home, ".claude"),
      path.join(ctx.cwd, ".claude"),
      path.join(ctx.home, ".claude.json"),
    ]);
  },

  async plan(ctx: TargetContext) {
    const root = scopeRoot(ctx, [".claude", "skills", "designpaca"], [".claude", "skills", "designpaca"]);
    return {
      target: this.id,
      scope: ctx.scope,
      root,
      actions: skillDirActions(root, ctx.skill),
      alreadyInstalled: await exists(path.join(root, "SKILL.md")),
    };
  },
};
