// Path: dexcom-receiver/src/main/java/org/glukit/dexcom/sync/DexcomDaemon.java
// public class DexcomDaemon {
//   private static Logger LOGGER = LoggerFactory.getLogger(DexcomDaemon.class);
//   private final UsbServices usbServices;
//   private final DexcomWatcher watcher;
// 
//   @Inject
//   public DexcomDaemon(UsbServices usbServices, DexcomWatcher watcher) {
//     this.usbServices = usbServices;
//     this.watcher = watcher;
//   }
// 
//   public void start() {
//     this.usbServices.addUsbServicesListener(watcher);
//     LibUsb.init(null);
//   }
// 
//   public void stop() {
//     this.usbServices.removeUsbServicesListener(watcher);
//     LibUsb.exit(null);
//   }
// }
// 
// Path: blood-shepherd-api/src/main/java/org/glukit/sync/api/BloodShepherdPreferences.java
// public class BloodShepherdPreferences {
//   public static final String LAST_SYNC = "last.sync";
//   private final Preferences preferences = Preferences.userNodeForPackage(this.getClass());
// 
//   public BloodShepherdPreferences() {
//   }
// 
//   public Instant getLastSyncTime() {
//     long value = this.preferences.getLong(LAST_SYNC, 0L);
//     return Instant.ofEpochMilli(value);
//   }
// 
//   public void saveLastSyncTime(Instant lastSyncTime) {
//     this.preferences.putLong(LAST_SYNC, lastSyncTime.toEpochMilli());
//   }
// }
// 
// Path: blood-shepherd-api/src/main/java/org/glukit/sync/api/BloodShepherdProperties.java
// public class BloodShepherdProperties extends Properties {
//   public static final String OUTPUT_PATH = "OUTPUT_PATH";
// }


import com.beust.jcommander.IParameterValidator2;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterDescription;
import com.beust.jcommander.ParameterException;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.glukit.dexcom.sync.DexcomDaemon;
import org.glukit.sync.api.BloodShepherdPreferences;
import org.glukit.sync.api.BloodShepherdProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.Instant;
import javax.usb.UsbException;
import java.io.File;
import static java.lang.String.format;
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 Alexandre Normand
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.glukit.app;




/**
 * Main class for the bloodsucker sync dexcomDaemon.
 *
 * @author alexandre.normand
 */
public class BloodShepherdTray {
  private static Logger LOGGER = LoggerFactory.getLogger(BloodShepherdTray.class);

  @Parameter(names = "-outputPath", required = true,
          description = "the output path of the exported files (make it something under your google drive local sync directory",
          validateWith = ExistingDirectoryValidator.class)
  String outputPath;

  @Parameter(names = "-sinceAsEpochMillis", required = false, description = "resets the value of the last sync time to the provided value")
    Long since;

  public BloodShepherdTray() {

  }

  public void run() {
    BloodShepherdProperties properties = new BloodShepherdProperties();
    properties.putAll(System.getProperties());
    properties.put(BloodShepherdProperties.OUTPUT_PATH, this.outputPath);

    BloodShepherdPreferences preferences = new BloodShepherdPreferences();
    if (this.since != null) {
      LOGGER.info("Overriding last sync time to {}.", this.since);
// Path: dexcom-receiver/src/main/java/org/glukit/dexcom/sync/DexcomDaemon.java
// public class DexcomDaemon {
//   private static Logger LOGGER = LoggerFactory.getLogger(DexcomDaemon.class);
//   private final UsbServices usbServices;
//   private final DexcomWatcher watcher;
// 
//   @Inject
//   public DexcomDaemon(UsbServices usbServices, DexcomWatcher watcher) {
//     this.usbServices = usbServices;
//     this.watcher = watcher;
//   }
// 
//   public void start() {
//     this.usbServices.addUsbServicesListener(watcher);
//     LibUsb.init(null);
//   }
// 
//   public void stop() {
//     this.usbServices.removeUsbServicesListener(watcher);
//     LibUsb.exit(null);
//   }
// }
// 
// Path: blood-shepherd-api/src/main/java/org/glukit/sync/api/BloodShepherdPreferences.java
// public class BloodShepherdPreferences {
//   public static final String LAST_SYNC = "last.sync";
//   private final Preferences preferences = Preferences.userNodeForPackage(this.getClass());
// 
//   public BloodShepherdPreferences() {
//   }
// 
//   public Instant getLastSyncTime() {
//     long value = this.preferences.getLong(LAST_SYNC, 0L);
//     return Instant.ofEpochMilli(value);
//   }
// 
//   public void saveLastSyncTime(Instant lastSyncTime) {
//     this.preferences.putLong(LAST_SYNC, lastSyncTime.toEpochMilli());
//   }
// }
// 
// Path: blood-shepherd-api/src/main/java/org/glukit/sync/api/BloodShepherdProperties.java
// public class BloodShepherdProperties extends Properties {
//   public static final String OUTPUT_PATH = "OUTPUT_PATH";
// }


// Path: blood-shepherd-app/src/main/java/org/glukit/app/BloodShepherdTray.java
import com.beust.jcommander.IParameterValidator2;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterDescription;
import com.beust.jcommander.ParameterException;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.glukit.dexcom.sync.DexcomDaemon;
import org.glukit.sync.api.BloodShepherdPreferences;
import org.glukit.sync.api.BloodShepherdProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.Instant;
import javax.usb.UsbException;
import java.io.File;
import static java.lang.String.format;

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 Alexandre Normand
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.glukit.app;




/**
 * Main class for the bloodsucker sync dexcomDaemon.
 *
 * @author alexandre.normand
 */
public class BloodShepherdTray {
  private static Logger LOGGER = LoggerFactory.getLogger(BloodShepherdTray.class);

  @Parameter(names = "-outputPath", required = true,
          description = "the output path of the exported files (make it something under your google drive local sync directory",
          validateWith = ExistingDirectoryValidator.class)
  String outputPath;

  @Parameter(names = "-sinceAsEpochMillis", required = false, description = "resets the value of the last sync time to the provided value")
    Long since;

  public BloodShepherdTray() {

  }

  public void run() {
    BloodShepherdProperties properties = new BloodShepherdProperties();
    properties.putAll(System.getProperties());
    properties.put(BloodShepherdProperties.OUTPUT_PATH, this.outputPath);

    BloodShepherdPreferences preferences = new BloodShepherdPreferences();
    if (this.since != null) {
      LOGGER.info("Overriding last sync time to {}.", this.since);
      preferences.saveLastSyncTime(Instant.ofEpochMilli(this.since));