/*
 * Copyright 2017 Open mHealth
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openmhealth.shim.withings.mapper;

import com.google.common.base.CaseFormat;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;


/**
 * @author Chris Schaefbauer
 * @author Emerson Farrugia
 */
public enum WithingsDevice {

    PULSE(16),
    AURA(32);

    private long magicNumber;

    private static Map<Long, WithingsDevice> map = new HashMap<>();

    static {
        for (WithingsDevice constant : WithingsDevice.values()) {
            map.put(constant.magicNumber, constant);
        }
    }

    public String getDisplayName() {
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, this.name());
    }

    WithingsDevice(final long magicNumber) {
        this.magicNumber = magicNumber;
    }

    /**
     * @param magicNumber a magic number
     * @return the constant corresponding to the magic number
     */
    public static Optional<WithingsDevice> findByMagicNumber(Integer magicNumber) {

        return Optional.ofNullable(map.get(magicNumber));
    }
}

@@ -641,51 +641,8 @@
 r;%0A%0A
-import com.google.common.base.CaseFormat;%0A%0A
 impo
@@ -817,16 +817,47 @@
     
-PULSE(16
+ACTIVITY_TRACKER(16, %22Activity tracker%22
 ),%0A 
@@ -866,16 +866,24 @@
  AURA(32
+, %22Aura%22
 );%0A%0A    
@@ -890,20 +890,19 @@
 private 
-long
+int
  magicNu
@@ -906,16 +906,48 @@
 cNumber;
+%0A    private String displayName;
 %0A%0A    pr
@@ -967,12 +967,15 @@
 Map%3C
-Long
+Integer
 , Wi
@@ -1169,22 +1169,47 @@
     
-public
+WithingsDevice(int magicNumber,
  String 
 getD
@@ -1208,12 +1208,9 @@
 ing 
-getD
+d
 ispl
@@ -1215,17 +1215,16 @@
 playName
-(
 ) %7B%0A    
@@ -1231,174 +1231,150 @@
     
-return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, this.name());%0A    %7D%0A%0A    WithingsDevice(final long magicNumber) %7B%0A        this.magicNumber = magicNumber
+this.magicNumber = magicNumber;%0A        this.displayName = displayName;%0A    %7D%0A%0A    public String getDisplayName() %7B%0A        return displayName
 ;%0A  

Update Withings device names