package com.scm.contract.tools;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zuo
 * @date 2024/6/5 9:37
 */

public class HumpLineAdopter {
    private static Pattern humpPattern = Pattern.compile("[A-Z]");

    public HumpLineAdopter() {
    }

    public static String humpToLine(String humpStr) {
        Matcher matcher = humpPattern.matcher(humpStr);
        StringBuffer sb = new StringBuffer();

        while(matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
        }

        matcher.appendTail(sb);
        return sb.toString();
    }

    public static String humpToLine(List<List<String>> orderList) {
        String orders = null;
        if (CollectionUtils.isNotEmpty(orderList)){
            List<String> strings = new ArrayList<>();
            for (List<String> list : orderList) {
                if (CollectionUtils.isNotEmpty(list) && list.size() == 2){
                    String humpStr = list.get(0);
                    String s = humpToLine(humpStr);
                    String s1 = list.get(1);
                    strings.add(String.join(" ", s,s1));
                }
            }
            if (CollectionUtils.isNotEmpty(strings)){
                orders = String.join(",", strings);
            }
        }
        return orders;
    }
}

