import { Hono } from 'hono';

import { DevicePermissionsRepo, PermissionsPayload } from '@/entities/device-permissions';

export const permissionsClientRouter = new Hono()
  .post('/', async (c) => {
    const deviceId = c.get('deviceId');
    const payload = PermissionsPayload.parse(await c.req.json());
    const row = await DevicePermissionsRepo.upsert(deviceId, payload);
    return c.json({ success: true, data: row });
  });
