package org.finos.waltz.web.endpoints.api;

import org.finos.waltz.service.software_catalog.VulnerabilityService;
import org.finos.waltz.web.ListRoute;
import org.finos.waltz.web.endpoints.Endpoint;
import org.finos.waltz.model.tally.TallyPack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static org.finos.waltz.web.WebUtilities.mkPath;
import static org.finos.waltz.web.WebUtilities.readIdSelectionOptionsFromBody;
import static org.finos.waltz.web.endpoints.EndpointUtilities.postForList;

@Service
public class VulnerabilityEndpoint  implements Endpoint {

    private static final String BASE_URL = mkPath("api", "vulnerability");

    private final VulnerabilityService vulnerabilityService;


    @Autowired
    public VulnerabilityEndpoint(VulnerabilityService vulnerabilityService) {
        this.vulnerabilityService = vulnerabilityService;
    }


    @Override
    public void register() {
        String countSeverityForVersionIdSelectorPath = mkPath(BASE_URL, "count-severities", "selector");

        ListRoute<TallyPack<String>> countSeverityForVersionIdSelectorRoute = (request, response)
                -> vulnerabilityService.countSeverityByVersionIdOptions(readIdSelectionOptionsFromBody(request));


        postForList(countSeverityForVersionIdSelectorPath, countSeverityForVersionIdSelectorRoute);
    }

}
