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

import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyChoiceService;
import edu.prlab.tyler.iotgateway.cloud.services.SensitiveUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GatewayController {
    private PrivacyChoiceService privacyChoiceService;
    private SensitiveUserService sensitiveUserService;

    @Autowired
    public GatewayController(PrivacyChoiceService privacyChoiceService,
                             SensitiveUserService sensitiveUserService) {
        this.privacyChoiceService = privacyChoiceService;
        this.sensitiveUserService = sensitiveUserService;
    }



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

    @PostMapping("user")
    public  ResponseEntity<SensitiveUser> setUser(@RequestBody SensitiveUser sensitiveUser) {
        return sensitiveUserService.add(sensitiveUser)
                    .map(ResponseEntity::ok)
                    .orElseGet(()->ResponseEntity.noContent().build());
    }
}
