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

import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Manufacturer;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Model;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicy;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.*;
import edu.prlab.tyler.iotgateway.cloud.services.DeviceService;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyPolicyReportService;
import edu.prlab.tyler.iotgateway.cloud.services.SensitiveUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class DefaultData implements ApplicationRunner {

    private DeviceService deviceService;
    private PrivacyPolicyReportService privacyPolicyReportService;
//    private SensitiveUserService sensitiveUserService;


    @Autowired
    public DefaultData(DeviceService deviceService,
                       PrivacyPolicyReportService privacyPolicyReportService,
                       SensitiveUserService sensitiveUserService) {
        this.deviceService = deviceService;
        this.privacyPolicyReportService = privacyPolicyReportService;
//        this.sensitiveUserService = sensitiveUserService;
    }

    @Override
    public void run(ApplicationArguments args) {

//        SensitiveUser user = SensitiveUser.builder()
//                .username("test")
//                .password("test")
//                .build();
//        sensitiveUserService.add(user);

        Device oxygenDevice = Device.builder()
                .udn("a1252c49-4188-4e6d-a32e-66604c664fb8")
                .name("指尖式血氧機")
                .type(Device.Type.Sensor)
                .manufacturer(Manufacturer.builder()
                        .name("Facelake")
                        .serialNumber("3176927193")
                        .url("http://facelake.com")
                        .build())
                .model(Model.builder()
                        .name("指尖式血氧機")
                        .description("本設備是為符合不同領域及照護應用而設計，並把這些特色融入小如指節的分析儀中，可在數秒內量測出準確可靠的血氧及心跳值。")
                        .url("https://www.amazon.com/Pulse-Oximeter-Blood-Oxygen-Monitor/dp/B00HXXO332")
                        .build())
                .UPC("B00HXXO332")
                .location("25.013068, 121.541651")
                .status(Device.Status.Disconnected)
                .build();

        deviceService.add(oxygenDevice);

        PrivacyPolicy oxygenPrivacyPolicy = PrivacyPolicy.builder()
                .id("abe5ca7b-780e-4857-87e6-014870fe0a3e")
                .description("本APP會蒐集使用者周遭溫度作為第三方資料之地區環境分析資料。")
                .collector(Collector.builder()
                        .name("AirRadio")
                        .email("airradio@gmail.com.tw")
                        .phone("0987654177")
                        .build())
                .remedies(Arrays.asList(Remedy.builder()
                        .type(Remedy.Type.LAW)
                        .build()))
                .statements(Arrays.asList(Statement.builder()
                        .consequence("a1252c49-4188-4e6d-a32e-66604c664fb9")
                        .purposes(Arrays.asList(Purpose.builder()
                                .type(Purpose.Type.PSEUDO_ANALYSIS)
                                .description("本APP會蒐集使用者周遭溫度作為第三方資料之地區環境分析資料。")
                                .build()))
                        .data(Arrays.asList(Datum.builder()
                                .type(Datum.Type.OTHER_CATEGORY)
                                .description("室溫資料")
                                .build()))
                        .recipients(Arrays.asList(Recipient.builder()
                                .entity("AirRadio")
                                .type(Recipient.Type.OURS)
                                .build()))
                        .retention(Retention.STATED_PURPOSE)
                        .build(), Statement.builder()
                        .consequence("a1252c49-4188-4e6d-a32e-66604c664fb9")
                        .purposes(Arrays.asList(Purpose.builder()
                                .type(Purpose.Type.PSEUDO_ANALYSIS)
                                .description("本APP會蒐集使用者周遭溫度作為第三方資料之地區環境分析資料。")
                                .build()))
                        .data(Arrays.asList(Datum.builder()
                                .type(Datum.Type.OTHER_CATEGORY)
                                .description("室溫資料")
                                .build()))
                        .recipients(Arrays.asList(Recipient.builder()
                                .entity("AirRadio")
                                .type(Recipient.Type.OURS)
                                .build()))
                        .retention(Retention.STATED_PURPOSE)
                        .build()
                ))
                .build();

        PrivacyPolicyReport oxygenPrivacyPolicyReport = PrivacyPolicyReport.builder()
                .id("0cfb6be3-6f0f-4e63-85b8-e9c936707c0a")
                .version("1.0")
                .description("本APP會蒐集使用者周遭溫度、濕度及空氣品質作為第三方資料之地區環境分析資料。")
                .device(oxygenDevice)
                .policies(Arrays.asList(oxygenPrivacyPolicy))
                .build();

        privacyPolicyReportService.add(oxygenPrivacyPolicyReport);

    }



}