package cn.pluss.platform.user.impl;


import cn.pluss.platform.user.UserPushService;
import cn.pluss.platform.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

/**
 * 静态推送方法工具类
 *
 * @author Djh
 */
@Service
public class GeneralPushUtil implements IPush {

    /**
     * 生产环境还是开发环境
     */
    public final static int PROD = 1;

    private static JGPushUtil jgPushUtil;

    private static MobPushUtil mobPushUtil;

    private static GetuiPushUtil getuiPushUtil;

    @Autowired
    private UserPushService userPushService;

    static {
        jgPushUtil = (JGPushUtil) JGPushUtil.getInstance();
        mobPushUtil = (MobPushUtil) MobPushUtil.getInstance();
        getuiPushUtil = (GetuiPushUtil) GetuiPushUtil.getInstance();
    }

    @Override
    public void sendAndroidByAlias(List<String> alias, String notificationTitle, String msgContent, String extrasParam) {
        try {
            // 安卓暂时用极光
            jgPushUtil.sendAndroidByAlias(alias, notificationTitle, msgContent, extrasParam);
            userPushService.push(alias, notificationTitle, msgContent, extrasParam);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sendIOSByAlias(List<String> alias, String notificationTitle, String msgContent, String extrasParam) {
        try {
            mobPushUtil.sendIOSByAlias(alias, notificationTitle, msgContent, extrasParam);
            userPushService.push(alias, notificationTitle, msgContent, extrasParam);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sendAllPlatByAlias(List<String> alias, String notificationTitle, String msgContent, String extrasParam) {
        try {

          /*  jgPushUtil.sendAndroidByAlias(alias, notificationTitle, msgContent, extrasParam);
            mobPushUtil.sendIOSByAlias(alias, notificationTitle, msgContent, extrasParam);
            userPushService.push(alias, notificationTitle, msgContent, extrasParam);*/

            MobV2PushUtil.sendSingleByAlias(alias, "快银到账1万元", "快银到账1万元", "payload:{voice:\"快银到账1万元\",type:\"1\"}}\"");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sendIOSAll(String notificationTitle, String msgContent, String extrasParam) {
        try {
            mobPushUtil.sendIOSAll(notificationTitle, msgContent, extrasParam);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sendAndroidAll(String notificationTitle, String msgContent, String extrasParam) {
        try {
            jgPushUtil.sendAndroidAll(notificationTitle, msgContent, extrasParam);
            getuiPushUtil.sendIOSAll(notificationTitle, msgContent, extrasParam);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sendAllPlatAll(String notificationTitle, String msgContent, String extrasParam) {
        try {
            //jgPushUtil.sendAndroidAll(notificationTitle, msgContent, extrasParam);
            //mobPushUtil.sendIOSAll(notificationTitle, msgContent, extrasParam);
            getuiPushUtil.sendIOSAll(notificationTitle, msgContent, extrasParam);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void sendAllPlatByUserIdChargeWithCoupon(List<String> alias, BigDecimal payMoney, BigDecimal coupon) {
        try {
            String content = "会员充值" + payMoney.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString() + "元";
            if (coupon != null && !BigDecimal.ZERO.equals(coupon.stripTrailingZeros())) {
                content += "，赠送" + coupon.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString() + "元";
            }
            sendAllPlatByAlias(alias, "会员充值通知", content, "3");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void sendAllPlatByUserIdConsumeWithCoupon(List<String> alias, BigDecimal payMoney, BigDecimal coupon) {
        try {
            String content = "会员消费" + payMoney.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString() + "元";
            if (coupon != null && !BigDecimal.ZERO.equals(coupon.stripTrailingZeros())) {
                content += "，返" + coupon.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString() + "元";
            }
            sendAllPlatByAlias(alias, "会员消费通知", content, "3");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void sendAllPlatByUserIdCancel(List<String> alias, BigDecimal payMoney, BigDecimal coupon) {
        try {
            sendAllPlatByAlias(alias, "订单取消支付", "订单取消支付", "3");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        List<String> alias = new ArrayList<>();
//        alias.add("1025");
//         alias.add("1775");
//         alias.add("1791");
//         alias.add("syb_1775");
//         alias.add("1792");
        // alias.add("1257");
        // alias.add("syb_828");
        // alias.add("syb_23999");
        // alias.add("syb_1257");
//        alias.add("7714");
        alias.add("7714");
        // alias.add("23999");
        // alias.add("3891");
        // alias.add("1791");
        // alias.add("69668");
        // alias.add("1775");
        // alias.add("828");
        // alias.add("43582");
        // alias.add("7266");
        // alias.add("33651");

//        sendAndroidByAlias(alias, "收银呗", "您有一笔催单请及时处理", "3");
//        sendAndroidByAlias(alias, "收银呗", "您有一个新的呼叫服务请及时处理", "3");
//        sendAndroidByAlias(alias, "收银呗", "收银呗线上店订单来了请及时处理", "3");

//        new GetuiConfig().init();
//         sendAllPlatByAlias(alias, "收银呗", "收银呗到账100.00元", "3");

        System.out.println("=========over========");
//        sendIOSAll("收银呗", "收银呗到账100022.00元", "3");
    }
}
