import { combineReducers } from 'redux';
import { deviceStateReducer } from "./DeviceReduxCoupling";

export const CHANGE_USER_NAME = "SET_USERNAME";
export const RESET_DEVICE_DATA = "RESET_DEVICE_DATA";


export const changeUsername = newUsername => ({
    type: CHANGE_USER_NAME,
    newUserName: newUsername,
});

export const startSession = () => ({
    type: START_SESSION
});

export const stopSession = () => ({
    type: STOP_SESSION
});

const INITIAL_SETTINGS = {
    theme: "hot",
    username: "",
    //swimTrackerHost: "192.168.178.107", // am pool
    swimTrackerHost: "192.168.42.1", // testgeraet

    analysis: {
        peaksPerLap: 30,
        windowSizeInSecs: 5,
        numMeasurementsPerSec: 10,

        kgFactor: 1.0 / 701.0, 

        peakDetector: 'SIMPLE', // either 'SIMPLE' or 'ZSCORE'
        peakDetectorSimpleThreshold: 2000,

        peakDetectorZScoreLag: 8, // peak detector z-score values
        peakDetectorZScoreThreshold: 2,
        peakDetectorZScoreInfluence: 0.1,

        activeTimeThreshold: 700,
        movingAverageWindowSize: 10*3,
    }
};


const settingsReducer = (state = INITIAL_SETTINGS, action) => {
    switch (action.type) {
        case CHANGE_USER_NAME:
            return { ...state, username: action.newUsername };
        default:
            return state
    }
};

export default combineReducers({
    settings: settingsReducer,
    deviceState: deviceStateReducer,
});