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

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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import static java.util.Arrays.asList;

@Component
public class DefaultData implements ApplicationRunner {

    private DeviceService deviceService;
    private PrivacyPolicyReportService privacyPolicyReportService;


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

    @Override
    public void run(ApplicationArguments args) {

        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())
                .access(Access.NON_IDENT)
                .dispute(Dispute.builder()
                        .relatedOrganization("地方法院")
                        .type(Dispute.Type.LAW).build())
                .remedies(asList(Remedy.builder()
                        .type(Remedy.Type.LAW)
                        .build()))
                .statements(asList(Statement.builder()
                        .consequence("a1252c49-4188-4e6d-a32e-66604c664fb9")
                        .purposes(asList(Purpose.builder()
                                .type(Purpose.Type.PSEUDO_ANALYSIS)
                                .description("本APP會蒐集使用者周遭溫度作為第三方資料之地區環境分析資料。")
                                .build()))
                        .data(asList(Datum.builder()
                                .type(Datum.Type.OTHER_CATEGORY)
                                .description("室溫資料")
                                .build()))
                        .recipients(asList(Recipient.builder()
                                .entity("AirRadio")
                                .type(Recipient.Type.OURS)
                                .build()))
                        .retention(Retention.STATED_PURPOSE)
                        .build(), Statement.builder()
                        .consequence("a1252c49-4188-4e6d-a32e-66604c664fb9")
                        .purposes(asList(Purpose.builder()
                                .type(Purpose.Type.PSEUDO_ANALYSIS)
                                .description("本APP會蒐集使用者周遭溫度作為第三方資料之地區環境分析資料。")
                                .build()))
                        .data(asList(Datum.builder()
                                .type(Datum.Type.OTHER_CATEGORY)
                                .description("室溫資料")
                                .build()))
                        .recipients(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(asList(oxygenPrivacyPolicy))
                .build();

        privacyPolicyReportService.add(oxygenPrivacyPolicyReport);

        Device sensorDevice = Device.builder()
                .udn("40ceb1e7-6834-4e6a-9305-57348a2b8d0c")
                .name("AirRadio多功能空氣品質感測器")
                .type(Device.Type.Sensor)
                .manufacturer(Manufacturer.builder()
                        .name("AirRadio")
                        .serialNumber("1234532545")
                        .url("http://www.airradio.cn/")
                        .build())
                .model(Model.builder()
                        .name("AirRadio Multi-functional air quality monitor")
                        .description("彩屏顯示、APP應用、多參數可選、本地歷史記錄、微信綁定、大屏顯示、遠程韌體升級、新版鐳射感測器、橫豎屏切換、綜合滿足用戶的多種需求。")
                        .url("https://www.amazon.com/AirRadio-Multi-functional-Humidity-Temperature-detector/dp/B0744D6C8X?pd_rd_wg=EKVyv&pd_rd_r=6cc9cf6f-635c-4be8-b973-ccc269ad6312&pd_rd_w=CGN5l&ref_=pd_gw_simh&pf_rd_r=7K2X6MZBXT0Y27KV4M6Z&pf_rd_p=b841581f-e864-5164-afa6-4c18a8348879")
                        .build())
                .upc("B0744D6C8X")
                .location("25.013068, 121.541651")
                .status(Device.Status.Disconnected)
                .build();

        deviceService.add(sensorDevice);

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

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

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

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

        privacyPolicyReportService.add(sensorPrivacyPolicyReport);
    }
}