package com.iqser.red.service.persistence.service.v1.api.shared.model.utils;

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

import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Position;

import lombok.experimental.UtilityClass;

@UtilityClass
public class ChangeUtils {

    public String buildVisualChange(String oldValue, String newValue) {

        String result = oldValue + " -> " + newValue;
        String shortenedOldValue = oldValue;
        String shortenedNewValue = oldValue;

        if (result.length() > 200) {
            if (oldValue.length() > 100) {
                shortenedOldValue = oldValue.substring(0, 100) + "...";
            }
            if (newValue.length() > 100) {
                shortenedNewValue = newValue.substring(0, 100) + "...";
            }
            result = shortenedOldValue + " -> " + shortenedNewValue;
        }

        return result;
    }


    public String prettifyPositions(List<Position> positions) {

        if (positions.size() == 1) {
            return positions.get(0).toString();
        } else {
            return positions.stream()
                    .map(Position::toString)
                    .collect(Collectors.joining(", ", "[", "]"));
        }
    }

}
