package com.sikey.wa04.business.infrastructure.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RequestParametersBuilder {
    private final Map<String, String> stringMap;
    private final List<String> excludeKeys = new ArrayList<>();

    public RequestParametersBuilder(Map<String, String> stringMap, String... excludeKeys) {
        this.stringMap = stringMap;
        this.excludeKeys.addAll(List.of(excludeKeys));
    }

    public String queryEncode() {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : stringMap.entrySet()) {
            if (excludeKeys.contains(entry.getKey())) {
                continue;
            }

            if (entry.getValue() == null) {
                continue;
            }

            if (!sb.isEmpty()) {
                sb.append("&");
            }

            sb.append(entry.getKey()).append("=").append(String.valueOf(entry.getValue()));
        }

//        return URLEncoder.encode(sb.toString(), StandardCharsets.UTF_8);
        return sb.toString();
    }
}
