import type { FastifyRequest, FastifyReply } from 'fastify';
import * as service from '../services/hallmarkGrade.service.js';

export async function listHandler(_request: FastifyRequest, _reply: FastifyReply) {
  return service.list();
}

export async function createHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { name } = request.body as { name: string };
  return service.create(name, request.user.id);
}

export async function updateHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { id } = request.params as { id: string };
  const { name } = request.body as { name: string };
  return service.updateItem(id, name, request.user.id);
}

export async function deleteHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { id } = request.params as { id: string };
  await service.remove(id, request.user.id);
  return { ok: true };
}
