package com.psg.dlsysinfo.dl_sysinfo_server.dto;

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

public class CveDTO {
    private String id;
    private String severity;
    private String description;
    private Double cvssScore;
    private String publishedDate;
    private String lastModifiedDate;

    // Constructor to map Cve entity with v4 -> v3 -> v2 fallback
    public CveDTO(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;
        }
    }

    // Getters and Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSeverity() {
        return severity;
    }

    public void setSeverity(String severity) {
        this.severity = severity;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getCvssScore() {
        return cvssScore;
    }

    public void setCvssScore(Double cvssScore) {
        this.cvssScore = cvssScore;
    }

    public String getPublishedDate() {
        return publishedDate;
    }

    public void setPublishedDate(String publishedDate) {
        this.publishedDate = publishedDate;
    }

    public String getLastModifiedDate() {
        return lastModifiedDate;
    }

    public void setLastModifiedDate(String lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }
}
