import { Hono } from 'hono';
import { z } from 'zod';

import { listAllDevices, revokeDeviceById } from '@/features/devices';

const idParam = z.string().min(1);

export const devicesAdminRouter = new Hono()
  .get('/', async (c) => {
    const devices = await listAllDevices();
    return c.json(devices);
  })
  .delete('/:id', async (c) => {
    const id = idParam.parse(c.req.param('id'));
    await revokeDeviceById(id);
    return c.body(null, 204);
  });
