package org.whitesource.agent.via.api;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Result of the Vulnerability Impact Analysis
 *
 * @author artiom.petrov
 */
public class VulnerabilityAnalysisResult implements Serializable {

    /* --- Static members --- */

    private static final long serialVersionUID = 8803589031348460812L;

    /* --- Members --- */

    // map from CVE to vulnerable elements
    private Map<String, Collection<VulnerableElement>> vulnerableElements;

    // map from CVE to vulnerable elements status
    private Map<String, VulnerabilityAnalysisResult.Status> vulnerableElementsStatus;

    // resource identifier
    private String matchValue;

    public enum Status {
        SUCCESS,
        NO_ELEMENTS_IN_DATABASE,
        TIMEOUT_FAILURE,
        FAILURE;
    }


    /* --- Constructor --- */

    public VulnerabilityAnalysisResult() {
        vulnerableElements = new HashMap<>();
        vulnerableElementsStatus = new HashMap<>();
    }

    public VulnerabilityAnalysisResult(String matchValue, Map<String, Collection<VulnerableElement>> vulnerableElements) {
        this.matchValue = matchValue;
        this.vulnerableElements = vulnerableElements;
    }

    public VulnerabilityAnalysisResult(String matchValue, Map<String, Collection<VulnerableElement>> vulnerableElements,
                                       Map<String, Status> vulnerableElementsStatus) {
        assert vulnerableElements.keySet().equals(vulnerableElementsStatus.keySet());
        this.matchValue = matchValue;
        this.vulnerableElements = vulnerableElements;
        this.vulnerableElementsStatus = vulnerableElementsStatus;
    }

    /* --- Overridden methods --- */

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof VulnerabilityAnalysisResult)) return false;
        VulnerabilityAnalysisResult that = (VulnerabilityAnalysisResult) o;
        return Objects.equals(vulnerableElements, that.vulnerableElements) &&
                Objects.equals(matchValue, that.matchValue);
    }

    @Override
    public int hashCode() {
        return Objects.hash(vulnerableElements, matchValue);
    }

    /* --- Getters / Setters --- */

    public String getMatchValue() {
        return matchValue;
    }

    public void setMatchValue(String matchValue) {
        this.matchValue = matchValue;
    }

    public Map<String, Collection<VulnerableElement>> getVulnerableElements() {
        return vulnerableElements;
    }

    public void setVulnerableElements(Map<String, Collection<VulnerableElement>> vulnerableElements) {
        this.vulnerableElements = vulnerableElements;
    }

    public Map<String, Status> getVulnerableElementsStatus() {
        return vulnerableElementsStatus;
    }

    public void setVulnerableElementsStatus(Map<String, Status> vulnerableElementsStatus) {
        this.vulnerableElementsStatus = vulnerableElementsStatus;
    }
}

@@ -880,17 +880,42 @@
  FAILURE
-;
+,%0A        CROSS_LANGUAGE;%0A
 %0A    %7D%0A%0A

add new status CROSS_LANGUAGE for via VulnerabilityAnalysisResult