import { copyFileSync, renameSync, existsSync } from 'node:fs';
import { join } from 'node:path';

// electron-icon-builder --flatten 은 build/icons/ 안에 icon.ico, icon.icns, <size>x<size>.png
// 들을 만든다. electron-builder 는 build/icon.ico, build/icon.icns, build/icon.png 를
// 기대 — 정규 위치로 옮긴다.
const buildDir = 'build';
const iconsDir = join(buildDir, 'icons');

const moves = [
  ['icon.ico', 'icon.ico'],
  ['icon.icns', 'icon.icns'],
];

for (const [src, dest] of moves) {
  const from = join(iconsDir, src);
  const to = join(buildDir, dest);
  if (existsSync(from)) {
    renameSync(from, to);
    console.log(`Moved: ${from} -> ${to}`);
  } else {
    console.error(`MISSING: ${from}`);
    process.exit(1);
  }
}

const png1024 = join(iconsDir, '1024x1024.png');
const pngOut = join(buildDir, 'icon.png');
if (existsSync(png1024)) {
  copyFileSync(png1024, pngOut);
  console.log(`Copied: ${png1024} -> ${pngOut}`);
} else {
  console.error(`MISSING: ${png1024}`);
  process.exit(1);
}
