package com.pack.modeler.assembler;

import com.pack.modeler.dto.ActivityDataDTO;
import com.pack.modeler.dto.DiagramDTO;
import com.pack.modeler.model.ActivityData;
import com.pack.modeler.model.DiagramData;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class BPMNAssambler {
    public Resource<DiagramDTO> toResource(DiagramData data) {
        DiagramDTO dto = new DiagramDTO(data.getLink(),
                data.getTraces(),
                data.getNodes(),
                data.getDensity(),
                data.getCohesion(),
                data.getCoupling(),
                data.getCnc());

        return new Resource<>(dto);
    }

    public Resources toResources(List<DiagramData> xmls){
        return new Resources(
                xmls.stream().map(this::toResource).collect(Collectors.toList())
        );
    }

    public Resource<ActivityDataDTO> toResourceActData(ActivityData data) {
        ActivityDataDTO dto = new ActivityDataDTO(
                data.getLink(),
                data.getKey(),
                data.getKeySeparator(),
                data.getCount());

        return new Resource<>(dto);
    }

    public Resources toResourcesActData(List<ActivityData> data){
        return new Resources(
                data.stream().map(this::toResourceActData).collect(Collectors.toList())
        );
    }

}
