package edu.prlab.tyler.iotgateway.gateway.controllers;

import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.gateway.services.PrivacyService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class GatewayController {

    private PrivacyService privacyService;

    public GatewayController(PrivacyService privacyService) {
        this.privacyService = privacyService;
    }

// TODO
//    @GetMapping("")
//    public ResponseEntity<Iterable<Device>> readDevicesOfUser() {
//
//    }

    @GetMapping("/privacy/{UDN}")
    public ResponseEntity<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@PathVariable(value = "UDN") String UDN) {
        return privacyService.getRelatedPrivacyPolicies(UDN)
                .map(ResponseEntity::ok)
                .orElseGet(()->ResponseEntity.noContent().build());
    }

    @PostMapping("/choice")
    public  ResponseEntity<PrivacyChoice> setPrivacyChoice(@RequestBody PrivacyChoice privacyChoice) {
        return privacyService.setPrivacyPolicyChoice(privacyChoice)
                .map(ResponseEntity::ok)
                .orElseGet(()->ResponseEntity.noContent().build());
    }
}
