@GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response invoices(@Context HttpServletRequest request) throws SQLException, IOException {
    authService.guardAuthenticatedUser(request);

    try (Connection c = dataSource.getConnection()) {
      List<UUID> ids = registrationsSqlMapper.all(c).map(x -> x.fst());
      List<RegistrationsSqlMapper.Registration> all = Option.somes(ids.traverseIO(ioify(c)).run());
      JsonRootNode overview =
          object(
              field(
                  "received",
                  array(
                      all.filter(x -> x.tuple.state == RegistrationState.RECEIVED)
                          .map(RegistrationsRestService::json))),
              field(
                  "invoicing",
                  array(
                      all.filter(x -> x.tuple.state == RegistrationState.INVOICING)
                          .map(RegistrationsRestService::json))),
              field(
                  "paid",
                  array(
                      all.filter(x -> x.tuple.state == RegistrationState.PAID)
                          .map(RegistrationsRestService::json))));
      return Response.ok(ArgoUtils.format(overview)).build();
    }
  }
  private int sub() throws Exception {
    Array<P2<String, Option<UUID>>> parse = outvoicePaidClient.parse(outvoicePaidClient.get());

    int i = 0;
    for (P2<String, Option<UUID>> p : parse) {
      RegistrationsSqlMapper.Registration registration;
      try (Connection c = dataSource.getConnection()) {
        c.setAutoCommit(false);

        Option<UUID> apiClientRef = p._2();
        if (apiClientRef.isNone()) continue;

        Option<UUID> registrationId =
            registrationsSqlMapper.invoiceReferenceToRegistrationId(c, apiClientRef.some());
        if (registrationId.isNone()) continue;

        registration = registrationsSqlMapper.one(c, registrationId.some()).some();
      }

      if (registration.tuple.state != RegistrationState.INVOICING) continue;

      markAsPaidService.markAsPaid(registration.id);
      i++;
    }
    return i;
  }
  @POST
  @Path("/mark-as-printed")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response markAsPrinted(@Context HttpServletRequest request, String body) throws Exception {
    authService.guardAuthenticatedUser(request);

    int i = 0;
    for (UUID uuid : registrationListRequest(body)) {
      try (Connection c = dataSource.getConnection()) {
        registrationsSqlMapper.replacePrintedNametag(c, uuid, Option.some(new PrintedNametag()));
      }
      i++;
    }

    return Response.ok(
            ArgoUtils.format(
                Result.success(String.format("Markerade %s namnbrickor som utskrivna.", i))))
        .build();
  }