// Path: src/main/java/com/mageddo/bookmarks/dao/SettingsDAO.java
// public interface SettingsDAO {
// 
//   List<SettingEntity> findAll();
// 
//   SettingEntity find(String key);
// 
//   void patch(SettingEntity settingEntity);
// }
// 
// 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);
//   }
// }


import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Singleton;
import com.mageddo.bookmarks.dao.SettingsDAO;
import com.mageddo.bookmarks.entity.SettingEntity;
import com.mageddo.bookmarks.exception.NotFoundException;
package com.mageddo.bookmarks.service;




@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) {
// Path: src/main/java/com/mageddo/bookmarks/dao/SettingsDAO.java
// public interface SettingsDAO {
// 
//   List<SettingEntity> findAll();
// 
//   SettingEntity find(String key);
// 
//   void patch(SettingEntity settingEntity);
// }
// 
// 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
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Singleton;
import com.mageddo.bookmarks.dao.SettingsDAO;
import com.mageddo.bookmarks.entity.SettingEntity;
import com.mageddo.bookmarks.exception.NotFoundException;

package com.mageddo.bookmarks.service;




@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()));