/**
   * Updates device class' equipment. None of following parameters are mandatory. Parameters, if
   * left unspecified, remains unchanged, instead setting parameter to null will null corresponding
   * value. In following JSON
   *
   * <p>name Equipment display name. code Equipment code. It's used to reference particular
   * equipment and it should be unique within a device class. type Equipment type. An arbitrary
   * string representing equipment capabilities. data Equipment data, a JSON object with an
   * arbitrary structure.
   *
   * <p><code>
   * {
   * "name": "equipment name",
   * "code": "equipment_code",
   * "type": "equipment_type",
   * "data": {/ * json object* /}
   * }
   * </code>
   *
   * @param classId id of class
   * @param eqId equipment id
   * @param equipmentUpdate Json object
   * @return empty response with status 201 in case of success, empty response with status 404, if
   *     there's no such record
   */
  @PUT
  @Path("/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response updateEquipment(
      @PathParam(DEVICE_CLASS_ID) long classId,
      @PathParam(ID) long eqId,
      @JsonPolicyApply(JsonPolicyDef.Policy.EQUIPMENT_PUBLISHED) EquipmentUpdate equipmentUpdate) {

    logger.debug("Update device class's equipment requested");

    if (!equipmentService.update(equipmentUpdate, eqId, classId)) {
      logger.debug(
          "Unable to update equipment. Equipment with id = {} for device class with id = {} not found",
          eqId,
          classId);
      return ResponseFactory.response(
          NOT_FOUND,
          new ErrorResponse(
              NOT_FOUND.getStatusCode(),
              String.format(Messages.EQUIPMENT_NOT_FOUND, eqId, classId)));
    }

    logger.debug("Update device class's equipment finished successfully");

    return ResponseFactory.response(NO_CONTENT);
  }
  /**
   * Will cascade deletes specified equipment and all data for this equipment for all devise of this
   * type.
   *
   * @param classId Device class id
   * @param eqId Equipment id
   * @return empty body, 204 if success, 404 if no record found
   */
  @DELETE
  @Path("/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response deleteEquipment(
      @PathParam(DEVICE_CLASS_ID) long classId, @PathParam(ID) long eqId) {

    logger.debug("Delete device class's equipment requested");
    equipmentService.delete(eqId, classId);
    logger.debug("Delete device class's equipment finished");

    return ResponseFactory.response(NO_CONTENT);
  }
  /**
   * Gets current state of device equipment. <code>
   * [
   * {
   * "id":1,
   * "timestamp": "1970-01-01 00:00:00.0",
   * "parameters":{/ *custom json object* /}
   * },
   * {
   * "id":2,
   * "timestamp": "1970-01-01 00:00:00.0",
   * "parameters":{/ *custom json object* /}
   * }
   * ]
   * <p/>
   * </code>
   *
   * @param classId device class id
   * @param eqId equipment id
   */
  @GET
  @Path("/{id}")
  public Response getEquipment(@PathParam(DEVICE_CLASS_ID) long classId, @PathParam(ID) long eqId) {

    logger.debug("Device class's equipment get requested");
    Equipment result = equipmentService.getByDeviceClass(classId, eqId);

    if (result == null) {
      logger.debug("No equipment with id = {} for device class with id = {} found", eqId, classId);
      return ResponseFactory.response(
          NOT_FOUND,
          new ErrorResponse(
              NOT_FOUND.getStatusCode(),
              String.format(Messages.EQUIPMENT_NOT_FOUND, eqId, classId)));
    }
    logger.debug("Device class's equipment get proceed successfully");

    return ResponseFactory.response(OK, result, EQUIPMENT_PUBLISHED);
  }