package org.synyx.urlaubsverwaltung.core.sicknote;

import com.google.common.base.Optional;

import org.joda.time.DateMidnight;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Service;

import org.synyx.urlaubsverwaltung.core.person.Person;

import java.util.List;


/**
 * Implentation for {@link org.synyx.urlaubsverwaltung.core.sicknote.SickNoteService}.
 *
 * @author  Aljona Murygina - murygina@synyx.de
 */
@Service
public class SickNoteServiceImpl implements SickNoteService {

    // TODO: Use Settings here!

    @Value("${sicknote.sickPay.limit}")
    private int sickPayLimit;

    @Value("${sicknote.sickPay.notification}")
    private int sickPayNotificationTime;

    private SickNoteDAO sickNoteDAO;

    @Autowired
    public SickNoteServiceImpl(SickNoteDAO sickNoteDAO) {

        this.sickNoteDAO = sickNoteDAO;
    }

    @Override
    public void save(SickNote sickNote) {

        sickNoteDAO.save(sickNote);
    }


    @Override
    public Optional<SickNote> getById(Integer id) {

        return Optional.fromNullable(sickNoteDAO.findOne(id));
    }


    @Override
    public List<SickNote> getByPersonAndPeriod(Person person, DateMidnight from, DateMidnight to) {

        return sickNoteDAO.findByPersonAndPeriod(person, from.toDate(), to.toDate());
    }


    @Override
    public List<SickNote> getByPeriod(DateMidnight from, DateMidnight to) {

        return sickNoteDAO.findByPeriod(from.toDate(), to.toDate());
    }


    @Override
    public List<SickNote> getSickNotesReachingEndOfSickPay() {

        DateMidnight endDate = DateMidnight.now().plusDays(sickPayNotificationTime);

        return sickNoteDAO.findSickNotesByMinimumLengthAndEndDate(sickPayLimit, endDate.toDate());
    }
}

@@ -188,67 +188,8 @@
 red;
-%0Aimport org.springframework.beans.factory.annotation.Value;
 %0A%0Aim
@@ -288,16 +288,141 @@
 .Person;
+%0Aimport org.synyx.urlaubsverwaltung.core.settings.Settings;%0Aimport org.synyx.urlaubsverwaltung.core.settings.SettingsService;
 %0A%0Aimport
@@ -662,81 +662,8 @@
  %7B%0A%0A
-    // TODO: Use Settings here!%0A%0A    @Value(%22$%7Bsicknote.sickPay.limit%7D%22)%0A
     
@@ -674,73 +674,38 @@
 ate 
+f
 in
-t sickPayLimit;%0A%0A    @Value(%22$%7Bsicknote.sickPay.notification%7D%22)
+al SickNoteDAO sickNoteDAO;
 %0A   
@@ -717,73 +717,45 @@
 ate 
+f
 in
-t sickPayNotificationTime;%0A%0A    private SickNoteDAO sickNoteDAO
+al SettingsService settingsService
 ;%0A%0A 
@@ -822,16 +822,49 @@
 kNoteDAO
+, SettingsService settingsService
 ) %7B%0A%0A   
@@ -896,24 +896,72 @@
 ickNoteDAO;%0A
+        this.settingsService = settingsService;%0A
     %7D%0A%0A    @
@@ -1645,24 +1645,84 @@
 ickPay() %7B%0A%0A
+        Settings settings = settingsService.getSettings();%0A%0A
         Date
@@ -1769,16 +1769,43 @@
 usDays(s
+ettings.getDaysBeforeEndOfS
 ickPayNo
@@ -1818,12 +1818,10 @@
 tion
-Time
+()
 );%0A%0A
@@ -1891,19 +1891,39 @@
 te(s
-ickPayLimit
+ettings.getMaximumSickPayDays()
 , en

Use settings object to get sick note configuration