package com.hubspot.singularity.data;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.utils.ZKPaths;

import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.hubspot.singularity.SingularityUserSettings;
import com.hubspot.singularity.config.SingularityConfiguration;
import com.hubspot.singularity.data.transcoders.Transcoder;

public class UserManager extends CuratorManager {

  private final Transcoder<SingularityUserSettings> settingsTranscoder;

  private static final String USER_ROOT = "/users";

  private static final String SETTINGS_ROOT = USER_ROOT + "/settings";

  @Inject
  public UserManager(CuratorFramework curator, SingularityConfiguration configuration, MetricRegistry metricRegistry,
                     Transcoder<SingularityUserSettings> settingsTranscoder) {
    super(curator, configuration, metricRegistry);
    this.settingsTranscoder = settingsTranscoder;
  }

  private String getUserSettingsPath(String id) {
    return ZKPaths.makePath(SETTINGS_ROOT, id);
  }

  public void deleteUserSettings(String id) {
    delete(getUserSettingsPath(id));
  }

  public Optional<SingularityUserSettings> getUserSettings(String id) {
    return getData(getUserSettingsPath(id), settingsTranscoder);
  }

  public void updateUserSettings(String id, SingularityUserSettings userSettings) {
    save(getUserSettingsPath(id), userSettings, settingsTranscoder);
  }

}

@@ -1105,20 +1105,20 @@
 ic void 
-dele
+upda
 teUserSe
@@ -1133,24 +1133,62 @@
 tring id
+, SingularityUserSettings userSettings
 ) %7B%0A    
 delete(g
@@ -1183,13 +1183,11 @@
     
-delet
+sav
 e(ge
@@ -1207,16 +1207,50 @@
 Path(id)
+, userSettings, settingsTranscoder
 );%0A  %7D%0A%0A
@@ -1397,36 +1397,36 @@
 %0A%0A  public void 
-upda
+dele
 teUserSettings(S
@@ -1437,54 +1437,16 @@
 g id
-, SingularityUserSettings userSettings
 ) %7B%0A    
 save
@@ -1433,35 +1433,37 @@
 tring id) %7B%0A    
-sav
+delet
 e(getUserSetting
@@ -1475,42 +1475,8 @@
 (id)
-, userSettings, settingsTranscoder
 );%0A 

Reorder UserSettings ZK methods more sensibly