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

import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyContent;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Optional;

@Service
public class PrivacyService {

    private RestTemplate template;

    private String cloudAddress;

    public PrivacyService() {
        this.template = new RestTemplate();
    }

    @Value("${iotgateway.cloud.address}")
    private void setCloudAddress(String cloudAddress) {
        this.cloudAddress = cloudAddress;
    }

    public Optional<PrivacyPolicyReport> getRelatedPrivacyPolicies(String Udn) {
        return Optional.ofNullable(template.getForObject(cloudAddress + "/device/privacy/" + Udn, PrivacyPolicyReport.class));
    }

    public Optional<PrivacyChoice> setPrivacyPolicyChoice(PrivacyChoice privacyChoice) {
        return Optional.of(privacyChoice)
                .map((choice) -> template.postForObject(cloudAddress + "/choice", choice, PrivacyChoice.class));
    }

    public void getPrivacyPolicyChoice(PrivacyContent content) {
    }
}
