import { AdminServiceError, blockUser } from '@/modules/admin/services/admin-users.service';
import type { AppContext } from '@/types/hono';
import type { AdminBlockUserInput } from '@repo/api-contract';

type BlockUserParams = { id: string };

export async function blockUserHandler(c: AppContext) {
  const { id } = c.req.valid('param' as never) as BlockUserParams;
  const body = c.req.valid('json' as never) as AdminBlockUserInput;

  try {
    await blockUser(id, body.banReason);
    return c.json({ message: 'Usuario bloqueado correctamente.' });
  } catch (error) {
    if (error instanceof AdminServiceError) {
      return c.json({ message: error.message }, error.status);
    }
    throw error;
  }
}
