"use strict";

const router = require("express").Router();

const { authenticateAdmin, audit } = require("../../middleware");
const AdminWalletsController = require("../../controllers/admin/walletsController");

// --------------------
// Wallets CRUD
// --------------------
router.get("/coins", authenticateAdmin, AdminWalletsController.listCoins);
router.get("/", authenticateAdmin, AdminWalletsController.listWallets);
router.post("/", authenticateAdmin, audit("wallets.create", "wallet"), AdminWalletsController.createWallet);


// --------------------
// Wallet Addresses CRUD
// --------------------
router.get("/addresses", authenticateAdmin, AdminWalletsController.listWalletAddresses);
router.post("/addresses", authenticateAdmin, audit("wallet_addresses.create", "wallet_address"), AdminWalletsController.createWalletAddress);
router.get("/addresses/:id", authenticateAdmin, AdminWalletsController.getWalletAddressById);
router.put("/addresses/:id", authenticateAdmin, audit("wallet_addresses.update", "wallet_address"), AdminWalletsController.updateWalletAddress);
router.delete("/addresses/:id", authenticateAdmin, audit("wallet_addresses.delete", "wallet_address"), AdminWalletsController.deleteWalletAddress);

// --------------------
// Wallet Actions
// --------------------
router.get("/:id", authenticateAdmin, AdminWalletsController.getWalletById);
router.put("/:id", authenticateAdmin, audit("wallets.update", "wallet"), AdminWalletsController.updateWallet);
router.delete("/:id", authenticateAdmin, audit("wallets.delete", "wallet"), AdminWalletsController.deleteWallet);
router.post("/:id/deposit", authenticateAdmin, audit("wallets.deposit", "wallet"), AdminWalletsController.depositToWallet);
router.post("/:id/withdraw", authenticateAdmin, audit("wallets.withdraw", "wallet"), AdminWalletsController.withdrawFromWallet);
router.post("/:id/swap", authenticateAdmin, audit("wallets.swap", "wallet"), AdminWalletsController.swapWallet);

module.exports = router;