/*
 *  Project:    moba-server
 *
 *  Copyright (C) 2016 Stefan Paproth <pappi-@gmx.de>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */

package moba.server.datatypes.objects;

import moba.server.datatypes.base.DayTime;
import moba.server.datatypes.base.Time;
import java.util.Map;

public class GlobalTimerData {
    protected DayTime curModelTime = new DayTime();
    protected int     multiplicator = 240;

    public int getMultiplicator() {
        return multiplicator;
    }

    public void setMultiplicator(int multiplicator)
    throws IllegalArgumentException {
        if(multiplicator < 60 || multiplicator > 3600) {
            throw new IllegalArgumentException("multiplicator out of range (< 60 || > 3600)");
        }
        if(3600 % multiplicator != 0) {
            throw new IllegalArgumentException("modulo 3600 check failed in multiplicator-setting");
        }
        this.multiplicator = multiplicator;
    }

    public DayTime getModelTime() {
        return curModelTime;
    }

    public void setModelTime(DayTime modelTime) {
        curModelTime = modelTime;
    }

    public void fromJsonObject(Map<String, Object> map) {
        curModelTime = new DayTime((String)map.get("curModelTime"));
        setMultiplicator(((Long)map.get("multiplicator")).intValue());
    }

    public boolean setTick() {
        curModelTime.setValue((curModelTime.getValue() + multiplicator) % (60 * 60 * 24 * 7));
        return curModelTime.isFullHour();
    }

    public boolean isTimeBetween(Time start, Time end) {
        int time = curModelTime.getValue() ;
        time %= (60 * 60 * 24);
        if(start.getTime() < time && end.getTime() > time) {
            return true;
        }
        return false;
    }
}

@@ -848,20 +848,24 @@
 pes.
-base.DayTime
+enumerations.Day
 ;%0Aim
@@ -969,24 +969,53 @@
 rotected Day
+  curModelDay;%0A    protected 
 Time curMode
@@ -1022,27 +1022,24 @@
 lTime = new 
-Day
 Time();%0A    
@@ -1053,19 +1053,16 @@
 ed int  
-   
 multipli
@@ -1287,19 +1287,18 @@
 cator %3E 
-360
+24
 0) %7B%0A   
@@ -1380,19 +1380,18 @@
 60 %7C%7C %3E 
-360
+24
 0)%22);%0A  
@@ -1390,32 +1390,33 @@
 0)%22);%0A        %7D%0A
+%0A
         if(3600 
@@ -1414,15 +1414,8 @@
  if(
-3600 %25 
 mult
@@ -1424,16 +1424,21 @@
 licator 
+%25 30 
 != 0) %7B%0A
@@ -1489,16 +1489,30 @@
 on(%22
+multiplicator 
 modulo 3
 600 
@@ -1507,18 +1507,16 @@
 modulo 3
-60
 0 check 
@@ -1629,16 +1629,168 @@
  Day
+ getCurModelDay() %7B%0A        return curModelDay;%0A    %7D%0A%0A    public void setCurModelDay(Day modelDay) %7B%0A        curModelDay = modelDay;%0A    %7D%0A%0A    public 
 Time get
 Mode
@@ -1785,16 +1785,19 @@
 Time get
+Cur
 ModelTim
@@ -1857,16 +1857,19 @@
 void set
+Cur
 ModelTim
@@ -1870,19 +1870,16 @@
 delTime(
-Day
 Time mod
@@ -1983,24 +1983,91 @@
 ect%3E map) %7B%0A
+        curModelDay = Day.valueOf((String)map.get(%22curModelDay%22));%0A
         curM
@@ -2081,19 +2081,16 @@
 e = new 
-Day
 Time((St
@@ -2229,32 +2229,35 @@
 ick() %7B%0A        
+if(
 curModelTime.set
@@ -2257,81 +2257,92 @@
 ime.
-setValue((curModelTime.getValue() + multiplicator) %25 (60 * 60 * 24 * 7));
+appendTime(multiplicator)) %7B%0A            curModelDay = curModelDay.next();%0A        %7D
 %0A   
@@ -2479,20 +2479,19 @@
 Time.get
-Valu
+Tim
 e() ;%0A  

factor from 60 to 240