#!/usr/bin/env bun
/**
 * Copies connect-to-humand-api templates to their destinations.
 * Safe to run multiple times — existing files are overwritten.
 */
import { copyFileSync, mkdirSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

const SKILL_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const TEMPLATES = join(SKILL_DIR, 'templates')

const FILES: Array<{ src: string; dest: string }> = [
  { src: '[...path].ts', dest: 'api/postgrest/[...path].ts' },
  { src: 'index.ts',     dest: 'api/postgrest/index.ts' },
  { src: 'postgrest.ts', dest: 'src/services/postgrest.ts' },
]

for (const { src, dest } of FILES) {
  mkdirSync(dirname(dest), { recursive: true })
  copyFileSync(join(TEMPLATES, src), dest)
  console.log(`  ✓ ${dest}`)
}
