package com.psg.dlsysinfo.dl_sysinfo_server.dto;

import com.psg.dlsysinfo.dl_sysinfo_server.entity.Cve;
import lombok.Getter;

@Getter
public class PublicCveDTO {
    private final String id;
    private final String description;
    private final String publishedDate;
    private final String lastModifiedDate;
    private final String severity;
    private final Double cvssScore;

    public PublicCveDTO(Cve cve) {
        this.id = cve.getId();
        this.description = cve.getDescription();
        this.publishedDate = cve.getPublishedDate();
        this.lastModifiedDate = cve.getLastModifiedDate();

        if (cve.getSeverityV4() != null && cve.getCvssScoreV4() != null) {
            this.severity = cve.getSeverityV4();
            this.cvssScore = cve.getCvssScoreV4();
        } else if (cve.getSeverityV3() != null && cve.getCvssScoreV3() != null) {
            this.severity = cve.getSeverityV3();
            this.cvssScore = cve.getCvssScoreV3();
        } else if (cve.getSeverityV2() != null && cve.getCvssScoreV2() != null) {
            this.severity = cve.getSeverityV2();
            this.cvssScore = cve.getCvssScoreV2();
        } else {
            this.severity = "UNKNOWN";
            this.cvssScore = 0.0;
        }
    }
}
