class NetworkController {

    @Path("/peer")
    @POST
    @Produces(MediaType.TEXT_HTML)
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Operation(
        summary = "Add new peer or replace existing.",
        description = "Add a peer to the list of known peers and attempt to connect to it.",
        security = @SecurityRequirement(name = "admin_api_key"),
        method = "POST",
        tags = {"networking"},
        responses = {
            @ApiResponse(responseCode = "200", description = "Successful execution",
                content = @Content(mediaType = "text/html",
                    schema = @Schema(implementation = PeerDTO.class)))
        }
    )
    @RolesAllowed("admin")
    public Response addOrReplacePeer(@Parameter(schema = @Schema(implementation = String.class, description = "the IP address or domain name of the peer")) @FormParam("peer") String peerAddress, @Context SecurityContext sc) {
        ResponseBuilder response = ResponseBuilder.ok();

        if (peerAddress == null) {
            return response.error(ApiErrors.MISSING_PARAM, "peer").build();
        }

        Peer peer = service.findOrCreatePeerByAddress(peerAddress);

        if (peer == null) {
            return response.error(ApiErrors.FAILED_TO_ADD_PEER, peerAddress).build();
        }

        boolean isNewlyAdded = service.addPeer(peer, peerAddress);
        PeerDTO dto = peerConverter.convert(peer);
        dto.setIsNewlyAdded(isNewlyAdded);

        return response.bind(dto).build();
    }

    public  NetworkController(Converter<Peer, PeerDTO> peerConverter, NetworkService service);

}