import { Router } from 'express';
import { getClients, blockClient, unblockClient } from '../services/unifiClient.js';

const router = Router();

router.get('/', async (req, res) => {
  try {
    const clients = await getClients();
    res.json(clients);
  } catch (err) {
    res.status(500).json({ error: err.message });
  }
});

router.post('/:mac/nuke', async (req, res) => {
  try {
    const { mac } = req.params;
    const result = await blockClient(decodeURIComponent(mac));
    res.json({ mac, blocked: true, result });
  } catch (err) {
    res.status(500).json({ error: err.message });
  }
});

router.post('/:mac/unnuke', async (req, res) => {
  try {
    const { mac } = req.params;
    const result = await unblockClient(decodeURIComponent(mac));
    res.json({ mac, blocked: false, result });
  } catch (err) {
    res.status(500).json({ error: err.message });
  }
});

export default router;
