package cn.sikey.selenium.util;

import lombok.experimental.UtilityClass;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.Random;

/**
 * @Author: nelson
 * @Date: 2025/6/28
 * @Description: base64（appid_ yyyyMMddHHmmssSSS+3位随机数）
 */
@UtilityClass
public class AppIdGeneratorUtil {

    /**
     * 生成uuid
     *
     * @param appId appid
     * @return
     */
    public String generateUuid(String appId) {
        // 生成时间戳 (yyyyMMddHHmmssSSS)
        String timestamp = LocalDateTime.now()
                .format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));

        // 生成3位随机数 (100-999)
        int randomNum = new Random().nextInt(900) + 100;

        // 组合成完整APPID
        appId = appId + "_" + timestamp + randomNum;

        // Base64编码
        return Base64.getEncoder()
                .encodeToString(appId.getBytes());
    }

}
