import { Router } from "express";
import db from "../db.js";

const router = Router();

router.get("/", (_req, res) => {
  const items = db
    .prepare("SELECT * FROM game_items ORDER BY type, name")
    .all() as Array<Record<string, unknown>>;
  const parsed = items.map((item) => ({
    ...item,
    effects: JSON.parse(item.effects as string),
    properties: JSON.parse(item.properties as string),
  }));
  res.json(parsed);
});

export default router;
