// Path: src/main/java/org/chorem/ecd/service/PowerManagementService.java
// @ApplicationScoped
// public class PowerManagementService {
// 
//     private static final Logger logger = LoggerFactory.getLogger(PowerManagementService.class);
// 
//     @Inject
//     protected SettingsDao settingsDao;
// 
//     public TvTimes getTvTimes() {
//         return settingsDao.getTvTimes();
//     }
// 
//     @TransactionRequired
//     public void setTvTimes(TvTimes tvTimes) {
//         validateTvTimes(tvTimes);
// 
//         settingsDao.setTvTimes(tvTimes);
//     }
// 
//     private void validateTvTimes(TvTimes tvTimes) throws InvalidArgumentException {
//         try {
//             LocalTime.parse(tvTimes.getWakeupTime());
//             LocalTime.parse(tvTimes.getSleepTime());
//         } catch(NullPointerException | DateTimeParseException e) {
//             logger.error(e.getMessage(), e);
//             throw new InvalidArgumentException("Les heures sont invalides");
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/chorem/ecd/model/settings/TvTimes.java
// public class TvTimes {
// 
//     private String wakeupTime;
// 
//     private String sleepTime;
// 
//     public TvTimes() {
// 
//     }
// 
//     public TvTimes(String wakeupTime, String sleepTime) {
//         this.wakeupTime = wakeupTime;
//         this.sleepTime = sleepTime;
//     }
// 
//     public String getWakeupTime() {
//         return wakeupTime;
//     }
// 
//     public void setWakeupTime(String wakeupTime) {
//         this.wakeupTime = wakeupTime;
//     }
// 
//     public String getSleepTime() {
//         return sleepTime;
//     }
// 
//     public void setSleepTime(String sleepTime) {
//         this.sleepTime = sleepTime;
//     }
// 
// }


import org.chorem.ecd.service.PowerManagementService;
import org.chorem.ecd.model.settings.TvTimes;
import spark.Request;
import spark.Response;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
package org.chorem.ecd.endpoint;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@ApplicationScoped
public class PowerManagementEndpoint extends Endpoint {

    @Inject
    protected PowerManagementService powerManagementService;

    @Override
    protected void init() {
        registerJsonProducer(ecdApiPath("/settings/tv-times"), this::getTvTimes);
        registerJsonConsumer(ecdApiPath("/settings/tv-times"), this::setTvTimes);
    }

    private Object getTvTimes(Request req, Response resp) {
        return powerManagementService.getTvTimes();
    }

    private Object setTvTimes(Request req, Response resp) throws Exception {
// Path: src/main/java/org/chorem/ecd/service/PowerManagementService.java
// @ApplicationScoped
// public class PowerManagementService {
// 
//     private static final Logger logger = LoggerFactory.getLogger(PowerManagementService.class);
// 
//     @Inject
//     protected SettingsDao settingsDao;
// 
//     public TvTimes getTvTimes() {
//         return settingsDao.getTvTimes();
//     }
// 
//     @TransactionRequired
//     public void setTvTimes(TvTimes tvTimes) {
//         validateTvTimes(tvTimes);
// 
//         settingsDao.setTvTimes(tvTimes);
//     }
// 
//     private void validateTvTimes(TvTimes tvTimes) throws InvalidArgumentException {
//         try {
//             LocalTime.parse(tvTimes.getWakeupTime());
//             LocalTime.parse(tvTimes.getSleepTime());
//         } catch(NullPointerException | DateTimeParseException e) {
//             logger.error(e.getMessage(), e);
//             throw new InvalidArgumentException("Les heures sont invalides");
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/chorem/ecd/model/settings/TvTimes.java
// public class TvTimes {
// 
//     private String wakeupTime;
// 
//     private String sleepTime;
// 
//     public TvTimes() {
// 
//     }
// 
//     public TvTimes(String wakeupTime, String sleepTime) {
//         this.wakeupTime = wakeupTime;
//         this.sleepTime = sleepTime;
//     }
// 
//     public String getWakeupTime() {
//         return wakeupTime;
//     }
// 
//     public void setWakeupTime(String wakeupTime) {
//         this.wakeupTime = wakeupTime;
//     }
// 
//     public String getSleepTime() {
//         return sleepTime;
//     }
// 
//     public void setSleepTime(String sleepTime) {
//         this.sleepTime = sleepTime;
//     }
// 
// }


// Path: src/main/java/org/chorem/ecd/endpoint/PowerManagementEndpoint.java
import org.chorem.ecd.service.PowerManagementService;
import org.chorem.ecd.model.settings.TvTimes;
import spark.Request;
import spark.Response;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

package org.chorem.ecd.endpoint;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@ApplicationScoped
public class PowerManagementEndpoint extends Endpoint {

    @Inject
    protected PowerManagementService powerManagementService;

    @Override
    protected void init() {
        registerJsonProducer(ecdApiPath("/settings/tv-times"), this::getTvTimes);
        registerJsonConsumer(ecdApiPath("/settings/tv-times"), this::setTvTimes);
    }

    private Object getTvTimes(Request req, Response resp) {
        return powerManagementService.getTvTimes();
    }

    private Object setTvTimes(Request req, Response resp) throws Exception {
        TvTimes tvTimes = getObject(req, TvTimes.class);