/*
 * (C) Copyright 2020 Netcentric - a Cognizant Digital Business
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package biz.netcentric.security.checkerdsl.model

/**
 * Basic vulnerability description which must be configured with each and every Security Check.
 * This information is supposed to be presented to the user and is required to analyze and to qualify the finding.
 *
 * @author thomas.hartmann@netcentric.biz
 * @since 04/2019
 */
class VulnerabilityDescription {

    String name = ""

    String description = ""

    String remediation = ""

    List<String> cve = []

    Severity severity = Severity.INFO

    static VulnerabilityDescription create(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = VulnerabilityDescription) Closure script) {
        VulnerabilityDescription description = new VulnerabilityDescription()
        script.setDelegate(description)
        script.resolveStrategy = Closure.DELEGATE_FIRST
        script()

        description
    }

    void name(String name) {
        this.name = name
    }

    void description(String description) {
        this.description = description
    }

    void remediation(String remediation) {
        this.remediation = remediation
    }

    /**
     * Add CWE code. See https://nvd.nist.gov/vuln/categories
     * @param cwes
     */

    void cve(String cwe) {
        this.cve.add(cwe)
    }

    void cve(List cwes) {
        this.cve.addAll(cwes)
    }

    void cve(String... cwes) {
        this.cve.addAll(cwes)
    }

    void severity(Severity severity){
        this.severity = severity
    }

    String toString() {
        "VulnerabilityDescription{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", remediation='" + remediation + '\'' +
                ", cve='" + cve.join(",") + '\'' +
                '}'
    }
}
