import express from "express";

import itemsService from "~/services/item/items";
import japaneseWeaponSwordSvc from "~/services/japanese/weapon/sword";
import europeanWeaponSwordSvc from "~/services/european/weapon/sword";
// import { errorHandler } from "~/routes/_main";

// eslint-disable-next-line new-cap
const router = express.Router();

// const getItem = "/:id";

router.get("/thumbnails", async function (req, res) {
	res.json(await itemsService.getThumbnails());
});

router.get("/", async function (req, res) {
	res.json(await itemsService.getList());
});

router.post("/", async function (req, res) {
	res.json(await itemsService.create(req.query.itemCategoryID));
});

router.put("/:id", async function (req, res) {
	res.json(await itemsService.update(req.params.id, req.body));
});

router.patch("/:id", async function (req, res) {
	// console.log("item patch attempt");
	// console.log("params:", req.params);
	// console.log("body:", req.body);
	res.json(await itemsService.patch(req.params.id, req.body));
});

router.get("/:id/general", async function (req, res) {
	res.json(await itemsService.getGeneral(req.params.id));
});

router.get("/:id/photos", async function (req, res) {
	res.json(await itemsService.getPhotos(req.params.id));
});

// TODO: MOVE JAP WEAP AND MED WEAP INTO SPECIFICS LIKE JAP ARMOR KABUTO DOES
// TODO: MOVE JAP WEAP AND MED WEAP INTO SPECIFICS LIKE JAP ARMOR KABUTO DOES
// TODO: MOVE JAP WEAP AND MED WEAP INTO SPECIFICS LIKE JAP ARMOR KABUTO DOES
// TODO: MOVE JAP WEAP AND MED WEAP INTO SPECIFICS LIKE JAP ARMOR KABUTO DOES
// TODO: MOVE JAP WEAP AND MED WEAP INTO SPECIFICS LIKE JAP ARMOR KABUTO DOES
// TODO: MOVE JAP WEAP AND MED WEAP INTO SPECIFICS LIKE JAP ARMOR KABUTO DOES

router.get("/:id/japanese/weapon/sword/size", async function (req, res) {
	res.json(await japaneseWeaponSwordSvc.getSize(req.params.id));
});
router.get("/:id/japanese/weapon/sword/blade", async function (req, res) {
	res.json(await japaneseWeaponSwordSvc.getBlade(req.params.id));
});
router.get("/:id/japanese/weapon/sword/handle", async function (req, res) {
	res.json(await japaneseWeaponSwordSvc.getHandle(req.params.id));
});
router.get("/:id/japanese/weapon/sword/fittings", async function (req, res) {
	res.json(await japaneseWeaponSwordSvc.getFittings(req.params.id));
});
router.get("/:id/japanese/weapon/sword/saya", async function (req, res) {
	res.json(await japaneseWeaponSwordSvc.getSaya(req.params.id));
});

router.patch("/:id/japanese/weapon/sword", async function (req, res) {
	res.json(await japaneseWeaponSwordSvc.patch(req.params.id, req.body));
});

/* *************************************************************************** */
/* *************************************************************************** */
/* MEDIEVAL WEAPONS                                                            */
/* *************************************************************************** */
/* *************************************************************************** */
router.get("/:id/medieval/weapon/sword/size", async function (req, res) {
	res.json(await europeanWeaponSwordSvc.getSize(req.params.id));
});

router.get("/:id/medieval/weapon/sword/blade", async function (req, res) {
	res.json(await europeanWeaponSwordSvc.getBlade(req.params.id));
});

router.get("/:id/medieval/weapon/sword/scabbard", async function (req, res) {
	res.json(await europeanWeaponSwordSvc.getScabbard(req.params.id));
});

router.patch("/:id/medieval/weapon/sword", async function (req, res) {
	res.json(await europeanWeaponSwordSvc.patch(req.params.id, req.body));
});

export default router;
