// Path: src/main/java/com/mageddo/bookmarks/entity/SettingEntity.java
// public class SettingEntity {
// 
//   private String key;
//   private String value;
// 
//   @JsonIgnore
//   private LocalDateTime update;
// 
//   public static RowMapper<SettingEntity> mapper() {
//     return (rs, rowNum) -> {
//       return new SettingEntity().setUpdate(JdbcHelper.getLocalDateTime(rs, "DAT_UPDATE"))
//           .setValue(rs.getString("DES_VALUE"))
//           .setKey(rs.getString("NAM_PROPERTY"));
//     };
//   }
// 
//   public String getValue() {
//     return value;
//   }
// 
//   public SettingEntity setValue(String value) {
//     this.value = value;
//     return this;
//   }
// 
//   public String getKey() {
//     return key;
//   }
// 
//   public SettingEntity setKey(String key) {
//     this.key = key;
//     return this;
//   }
// 
//   public LocalDateTime getUpdate() {
//     return update;
//   }
// 
//   public SettingEntity setUpdate(LocalDateTime update) {
//     this.update = update;
//     return this;
//   }
// 
//   public enum Setting {
// 
//     CODE_BLOCK_MAX_HEIGHT, //
//     MOBILE_CODE_BLOCK_MAX_HEIGHT, //
//     CODE_STYLE_TAB_SIZE, //
//     CODE_STYLE_TAB_STYLE, //
//     CODE_STYLE_SHOW_WHITESPACES, //
// 
//     /**
//      * HTML which should be put inside the &lt;head&gt; tag
//      */
//     PUBLIC_PAGES_HEADER_HTML, //
//     ;
//   }
// }
// 
// Path: src/main/java/com/mageddo/bookmarks/exception/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//   public NotFoundException(String message) {
//     super(message);
//   }
// }
// 
// Path: src/main/java/com/mageddo/bookmarks/service/SettingsService.java
// @Singleton
// public class SettingsService {
// 
//   private final SettingsDAO settingsDAO;
// 
//   public SettingsService(SettingsDAO settingsDAO) {
//     this.settingsDAO = settingsDAO;
//   }
// 
//   public Map<String, String> findAllAsMap() {
//     final List<SettingEntity> settings = settingsDAO.findAll();
//     final Map<String, String> settingsMap = new LinkedHashMap<>();
//     for (SettingEntity setting : settings) {
//       settingsMap.put(setting.getKey(), setting.getValue());
//     }
//     return settingsMap;
//   }
// 
//   public List<SettingEntity> findAll() {
//     return settingsDAO.findAll();
//   }
// 
//   public SettingEntity findSetting(String key) {
//     return settingsDAO.find(key);
//   }
// 
//   public boolean patch(SettingEntity settingEntity) {
//     final SettingEntity dbSettingEntity = settingsDAO.find(settingEntity.getKey());
//     if (dbSettingEntity == null) {
//       throw new NotFoundException(String.format("parameter doesn't exists %s", settingEntity.getKey()));
//     }
//     dbSettingEntity.setValue(settingEntity.getValue());
//     dbSettingEntity.setUpdate(LocalDateTime.now());
//     settingsDAO.patch(dbSettingEntity);
//     return true;
//   }
// 
//   public void patch(List<SettingEntity> settings) {
//     for (SettingEntity setting : settings) {
//       this.patch(setting);
//     }
//   }
// }


import com.mageddo.bookmarks.entity.SettingEntity;
import com.mageddo.bookmarks.exception.NotFoundException;
import com.mageddo.bookmarks.service.SettingsService;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Patch;
import io.micronaut.http.annotation.QueryValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unbescape.html.HtmlEscape;
import java.util.List;
import java.util.stream.Collectors;
import static io.micronaut.http.HttpResponse.badRequest;
import static io.micronaut.http.HttpResponse.notFound;
import static io.micronaut.http.HttpResponse.ok;
    try {
      return ok(settingsService.findAllAsMap());
    } catch (Exception e) {
      logger.error("status=cant-load-settings, msg={}", e.getMessage(), e);
      return badRequest("Could not read settings");
    }
  }

  @Get("/api/v{version:[12]}.0/settings")
  public HttpResponse _2(String version) {
    try {
      return ok(settingsService.findAll());
    } catch (Exception e) {
      logger.error("status=cant-load-settings, msg={}", e.getMessage(), e);
      return badRequest("Could not read settings");
    }
  }

  @Get("/api/v{version:[12]}.0/settings?key")
  public HttpResponse _3(String version, @QueryValue("key") String key) {
    try {
      return ok(settingsService.findSetting(key));
    } catch (Exception e) {
      logger.error("status=cant-load-settings, msg={}", e.getMessage(), e);
      return badRequest("Could not read settings");
    }
  }

  @Patch(value = "/api/v{version:[12]}.0/settings", consumes = MediaType.APPLICATION_JSON,
      produces = MediaType.APPLICATION_JSON)
// Path: src/main/java/com/mageddo/bookmarks/entity/SettingEntity.java
// public class SettingEntity {
// 
//   private String key;
//   private String value;
// 
//   @JsonIgnore
//   private LocalDateTime update;
// 
//   public static RowMapper<SettingEntity> mapper() {
//     return (rs, rowNum) -> {
//       return new SettingEntity().setUpdate(JdbcHelper.getLocalDateTime(rs, "DAT_UPDATE"))
//           .setValue(rs.getString("DES_VALUE"))
//           .setKey(rs.getString("NAM_PROPERTY"));
//     };
//   }
// 
//   public String getValue() {
//     return value;
//   }
// 
//   public SettingEntity setValue(String value) {
//     this.value = value;
//     return this;
//   }
// 
//   public String getKey() {
//     return key;
//   }
// 
//   public SettingEntity setKey(String key) {
//     this.key = key;
//     return this;
//   }
// 
//   public LocalDateTime getUpdate() {
//     return update;
//   }
// 
//   public SettingEntity setUpdate(LocalDateTime update) {
//     this.update = update;
//     return this;
//   }
// 
//   public enum Setting {
// 
//     CODE_BLOCK_MAX_HEIGHT, //
//     MOBILE_CODE_BLOCK_MAX_HEIGHT, //
//     CODE_STYLE_TAB_SIZE, //
//     CODE_STYLE_TAB_STYLE, //
//     CODE_STYLE_SHOW_WHITESPACES, //
// 
//     /**
//      * HTML which should be put inside the &lt;head&gt; tag
//      */
//     PUBLIC_PAGES_HEADER_HTML, //
//     ;
//   }
// }
// 
// Path: src/main/java/com/mageddo/bookmarks/exception/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//   public NotFoundException(String message) {
//     super(message);
//   }
// }
// 
// Path: src/main/java/com/mageddo/bookmarks/service/SettingsService.java
// @Singleton
// public class SettingsService {
// 
//   private final SettingsDAO settingsDAO;
// 
//   public SettingsService(SettingsDAO settingsDAO) {
//     this.settingsDAO = settingsDAO;
//   }
// 
//   public Map<String, String> findAllAsMap() {
//     final List<SettingEntity> settings = settingsDAO.findAll();
//     final Map<String, String> settingsMap = new LinkedHashMap<>();
//     for (SettingEntity setting : settings) {
//       settingsMap.put(setting.getKey(), setting.getValue());
//     }
//     return settingsMap;
//   }
// 
//   public List<SettingEntity> findAll() {
//     return settingsDAO.findAll();
//   }
// 
//   public SettingEntity findSetting(String key) {
//     return settingsDAO.find(key);
//   }
// 
//   public boolean patch(SettingEntity settingEntity) {
//     final SettingEntity dbSettingEntity = settingsDAO.find(settingEntity.getKey());
//     if (dbSettingEntity == null) {
//       throw new NotFoundException(String.format("parameter doesn't exists %s", settingEntity.getKey()));
//     }
//     dbSettingEntity.setValue(settingEntity.getValue());
//     dbSettingEntity.setUpdate(LocalDateTime.now());
//     settingsDAO.patch(dbSettingEntity);
//     return true;
//   }
// 
//   public void patch(List<SettingEntity> settings) {
//     for (SettingEntity setting : settings) {
//       this.patch(setting);
//     }
//   }
// }


// Path: src/main/java/com/mageddo/bookmarks/apiserver/SettingsController.java
import com.mageddo.bookmarks.entity.SettingEntity;
import com.mageddo.bookmarks.exception.NotFoundException;
import com.mageddo.bookmarks.service.SettingsService;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Patch;
import io.micronaut.http.annotation.QueryValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unbescape.html.HtmlEscape;
import java.util.List;
import java.util.stream.Collectors;
import static io.micronaut.http.HttpResponse.badRequest;
import static io.micronaut.http.HttpResponse.notFound;
import static io.micronaut.http.HttpResponse.ok;

    try {
      return ok(settingsService.findAllAsMap());
    } catch (Exception e) {
      logger.error("status=cant-load-settings, msg={}", e.getMessage(), e);
      return badRequest("Could not read settings");
    }
  }

  @Get("/api/v{version:[12]}.0/settings")
  public HttpResponse _2(String version) {
    try {
      return ok(settingsService.findAll());
    } catch (Exception e) {
      logger.error("status=cant-load-settings, msg={}", e.getMessage(), e);
      return badRequest("Could not read settings");
    }
  }

  @Get("/api/v{version:[12]}.0/settings?key")
  public HttpResponse _3(String version, @QueryValue("key") String key) {
    try {
      return ok(settingsService.findSetting(key));
    } catch (Exception e) {
      logger.error("status=cant-load-settings, msg={}", e.getMessage(), e);
      return badRequest("Could not read settings");
    }
  }

  @Patch(value = "/api/v{version:[12]}.0/settings", consumes = MediaType.APPLICATION_JSON,
      produces = MediaType.APPLICATION_JSON)
  public HttpResponse _4(String version, @Body List<SettingEntity> settings) {