package org.tio.sitexxx.service.service.jpush.honor;

import org.tio.sitexxx.service.service.jpush.honor.android.AndroidNotification;
import org.tio.sitexxx.service.service.jpush.honor.android.BadgeNotification;
import org.tio.sitexxx.service.service.jpush.honor.android.ClickAction;
import org.tio.sitexxx.service.service.jpush.honor.message.AndroidConfig;
import org.tio.sitexxx.service.service.jpush.honor.message.Message;
import org.tio.sitexxx.service.service.jpush.honor.message.Notification;
import org.tio.sitexxx.service.service.jpush.honor.response.SendResponse;
import org.tio.sitexxx.service.service.jpush.honor.util.InitHonorUtils;
import org.tio.sitexxx.service.service.jpush.JPushService;
import org.tio.sitexxx.service.service.jpush.honor.messaging.HonorApp;
import org.tio.sitexxx.service.service.jpush.honor.messaging.HonorMessaging;

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

/**
 * <pre>
 *    @author : vagrancy
 *    e-mail : 18050829067@163.com
 *    time   : 2025-02-26 14:45
 *    desc   : 荣耀
 * </pre>
 */
public class Honor {
    public static void send(List<String> token, String title, String msg) {
        HonorApp app = InitHonorUtils.initializeApp();
        HonorMessaging honorMessaging = HonorMessaging.getInstance(app);

        Notification notification = Notification.builder()
                .setTitle(title)
                .setBody(msg)
                .build();

        AndroidNotification androidNotification = AndroidNotification.builder()
                .setClickAction(ClickAction.builder().setType(3).build())
                .setNotifyId(486)
                .setTitle(msg)
                .setBody(msg)
                .setBadge(BadgeNotification.builder().setAddNum(1)
                        .setBadgeClass("com.tengabai.show.feature.splash.SplashActivity").build())
                .build();

        AndroidConfig androidConfig = AndroidConfig.builder()
                .setNotification(androidNotification)
                .build();

        Message message = Message.builder()
                .setNotification(notification)
                .setAndroidConfig(androidConfig)
                .addAllToken(token)
                .build();
        try {
            SendResponse response = honorMessaging.sendMessage(message);
            if (JPushService.IS_DEBUG) {
                System.out.println("code:"+response.getCode()+",msg:"+response.getMsg()+",requestId:"+response.getData());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void send(String token, String title, String msg) {
        List<String> tokens = new ArrayList<>();
        tokens.add(token);
        send(tokens, title, msg);
    }
}
