import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;

import quant.rich.emoney.util.VersionComparator;

public class WeibaPlayground {
    
    private static final short[] XCUtil_short = new short[]{2176, 1289, 2869, 2868, 2854, 2893, 2904, 2219, 2231, 2231, 2227, 2297, 2284, 2284, 2228, 2214, 2218, 2209, 2210, 2285, 2215, 2230, 2220, 2216, 2210, 2218, 2234, 2210, 2285, 2208, 2220, 2222, 2284, 2221, 2214, 2228, 2227, 2219, 2220, 2221, 2214, 2285, 2227, 2219, 2227, 2300, 2218, 2215, 2302, 1330, 1378, 1393, 1382, 1321, 1971, 2022, 2044, 2034, 2043, 1960};
    
    public static void main(String[] args) throws IOException {
        System.out.println(
                ((Object)"ۤۢۢ").hashCode()
                
                );
        System.out.println(decodeShort(XCUtil_short, 1, 1, 1397));
        // (1745665457, MTc0NTY2NTQ1N3xkZjJkOThjYw==)
        // FM%5C%29GMR%2BGMJ*G%2CqdScCdHMacRp%3D%3D
        Path path = Path.of("E:\\eclipse-workspace\\emoney-auto\\conf\\system\\emoneyRequest.androidChromeVersions.json");
        String str = Files.readString(path);
        
        ObjectMapper mapper = new ObjectMapper();
        ArrayNode node = (ArrayNode) mapper.readTree(str);
        
        List<String> ver = mapper.convertValue(node, new TypeReference<List<String>>() {});
        ver.sort(VersionComparator.INSTANCE.reversed());
        Set<String> verSet = new LinkedHashSet<>(ver);
        ver = List.copyOf(verSet);
        
        ArrayNode ja = mapper.valueToTree(verSet);
        Files.writeString(path, ja.toPrettyString());
        //System.out.println(ccc("1745665457", "MTc0NTY2NTQ1N3xkZjJkOThjYw=="));
    }
    
    public static String decodeShort(short[] sArr, int i, int i2, int i3) {
        char[] cArr = new char[i2];
        for (int i4 = 0; i4 < i2; i4++) {
            cArr[i4] = (char) (sArr[i + i4] ^ i3);
        }
        return new String(cArr);
    }
    
    public static String ccc(String var0, String var1) throws UnsupportedEncodingException {
        String decoded = new String(Base64.getDecoder().decode(var1)).trim();
        StringBuilder sb = new StringBuilder();

        // 获取时间戳最后一位作为减法因子（如 1745660488 → 8）
        int offset = var0.charAt(9) - '0'; // var0 是时间戳

        for (char ch : decoded.toCharArray()) {
            if (ch == '=') continue;
            sb.append((char)(ch - offset));
        }

        return URLEncoder.encode(sb.toString(), "UTF-8");
    }

}
