package com.tzld.piaoquan.growth.common.utils;

import org.apache.commons.lang3.StringUtils;

import static com.tzld.piaoquan.growth.common.common.constant.MessageConstant.defaultName;

public class MessageUtil {

    public static Long getVideoId(String page) {
        String translate = URLUtil.translate(page);
        if (translate.contains("id=")) {
            String videoId = translate.split("id=")[1].split("&")[0];
            if (StringUtils.isNotEmpty(videoId) && StringUtils.isNumeric(videoId)) {
                return Long.parseLong(videoId);
            }
        }
        return null;
    }

    public static String getRootSourceId(String page) {
        if(StringUtils.isEmpty(page)){
            return null;
        }
        if(!page.contains("rootSourceId")){
            return null;
        }
        String translate = URLUtil.translate(page);
        if (translate.contains("rootSourceId=")) {
            String rootSourceId = translate.split("rootSourceId=")[1].split("&")[0];
            if (StringUtils.isNotEmpty(rootSourceId)) {
                return rootSourceId;
            }
        }
        return null;
    }

    public static String getName(String remark) {
        return String.format(defaultName, DateUtil.getDayDateString("MMdd"), remark);
    }

    public static void main(String[] args) {
        String url = "pages/category?jumpPage=pages%2Fuser-videos%3FfromGzh%3D1%26rootShareId%3D450ba747-3375-4cf3-a908-1b2772e181a7%26id%3D13889690%26shareId%3D450ba747-3375-4cf3-a908-1b2772e181a7%26rootSourceId%3Ddaitou_tencentgzh_20251212_13889690_f7221c51%26shareTitleId%3D14889690%26shareImageId%3D87473466%26shareImageUrl%3Dhttps%253A%252F%252Frescdn.yishihui.com%252Flongvideo%252Fpic%252F44a75a67b65244ef80a8dca6341584fc1765518383424";
        System.out.println(getRootSourceId(url));
    }
}
