package com.kxs.system.api.util;

import com.kxs.system.api.model.KxsUserMsg;

import java.time.LocalDateTime;
import java.util.List;

/**
 *  个人消息模板
 *
 * @author Lxq
 * @date 2023-12-14
 */
public class MsgTemplateUtil {

    /**
     * 来新人啦
     *
     * @return {@link String}
     */
    public static KxsUserMsg newUserPush(Integer userId){

        String title = "来新人啦";

        String content = "您的创业邦系统有新人加入了，请进入客小爽-我的创客中查看!";

        return MsgTemplateUtil.createTextMsg(userId, title, "", content);
    }

    /**
     * 机具驳回通知
     *
     * @return {@link String}
     */
    public static KxsUserMsg orderCancel(Integer userId, List<String> snList, String brandName, String storeName, String storePhone, String orderSn){

        String title = "机具驳回通知";
        //推送个人消息
        String content = "<div class='16'>您申请的" +
                snList.size() +
                "台" +
                brandName +
                "已被" +
                storeName +
                "驳回，<br/>" +
                "请您重新发起申请!<br/>" +
                "订单号：" + orderSn + "<br/>" +
                "驳回时间：" + LocalDateTime.now() + "<br/>" +
                "联系方式：" + storePhone + "<br/>" +
                "机具类型：" + brandName + "<br/>" +
                "兑换券/机：" + String.join(",", snList)+ "<br/></div>";

        return MsgTemplateUtil.createTextMsg(userId, title, "", content);
    }


    /**
     * 机具回收通知
     *
     * @param snList   SN列表
     * @param brandName 品牌名
     * @param userId   用户 ID
     * @param userCode 用户代码
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg machineRecycleNote(List<String> snList, String brandName, Integer userId, String userCode) {
        String title = "机具回收通知";
        String summary = "您收到来自创客"+userCode+"机具回收订单，请打开仓库管理及时处理！";
        StringBuilder content = new StringBuilder();
        for (String sn : snList) {
            content.append("<div class='16'>").append(brandName).append(":").append(sn).append(",</div>");
        }

        return MsgTemplateUtil.createHtmlMsg(userId, title, summary, content.toString());

    }

    /**
     * 预发机撤回通知
     *
     * @param posSn      POS SN机
     * @param userId 发送用户 ID
     * @param userCode   用户代码
     * @param username   用户名
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg cancelAdvanceNote(String posSn, Integer userId, String userCode, String username) {
        String title = "预发机撤回通知";

        String summary = "已撤回创客："+userCode + username+"的预发机 SN：" + posSn;

        return MsgTemplateUtil.createTextMsg(userId, title, summary, summary);
    }

    /**
     * 预发机撤回通知
     *
     * @param posSn         POS SN机
     * @param userId      到用户 ID
     * @param warehouseName 仓库名称
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg cancelAdvanceNote(String posSn, Integer userId, String warehouseName) {

        String title = "预发机撤回通知";

        String summary = warehouseName + "已撤回机具号："+ posSn +"的预发机";

        return MsgTemplateUtil.createTextMsg(userId, title, summary, summary);
    }


    /**
     * 预发货确认通知 仓库
     *
     * @param userId        用户 ID
     * @param userCode      用户代码
     * @param username      用户名
     * @param warehouseName 仓库名称
     * @param brandName          名字
     * @param snList        SN列表
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg confirmAdvanceMachineWarehoiuseNote(Integer userId, String userCode, String username, String warehouseName, String brandName, List<String> snList) {
        String title = "预发货确认通知";
        String summary = "创客："+userCode + username + "  已确认接收来自您的: "+warehouseName+"--"+brandName+", 的 "+snList.size()+" 台 预发货机具";

        StringBuilder content = new StringBuilder("<div class='16'>" + "创客：" + userCode + username + "  已确认接收来自您的: " + warehouseName + "--" + brandName + ", 的 " + snList.size() + " 台 预发货机具<br/>");
        for (String sn : snList) {
            content.append("<p class='16'>SN：").append(sn).append(",</p><br/>");
        }
        content.append("*注：请仔细核对SN后确认，确认接收机具后若出现机具丢失等问题，则需承担相应损失。");
        content.append("</div>");

        return MsgTemplateUtil.createHtmlMsg(userId, title, summary, content.toString());
    }

    /**
     * 预发货确认通知 用户
     *
     * @param userId             userId
     * @param warehouseName 仓库名称
     * @param brandName     品牌
     * @param snList        SN列表
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg confirmAdvanceMachineUserNote(int userId, String warehouseName, String brandName, List<String> snList) {

        String title = "预发货确认通知";
        String summary = "已确认接收来自: "+warehouseName+"--"+ brandName + ", 的 "+snList.size()+" 台 预发货机具";

        StringBuilder content = new StringBuilder("<div class='16'>已确认接收来自: " + warehouseName + "--" + brandName + ", 的 " + snList.size() + " 台 预发货机具<br/>");
        for (String sn : snList) {
            content.append("<p class='16'>SN：").append(sn).append(",</p><br/>");
        }
        content.append("*注：请仔细核对SN后确认，确认接收机具后若出现机具丢失等问题，则需承担相应损失。");
        content.append("</div>");

        return MsgTemplateUtil.createHtmlMsg(userId, title, summary, content.toString());

    }


    /**
     * 预发货拒绝通知
     *
     * @param userId        用户 ID
     * @param userCode      用户代码
     * @param username      用户名
     * @param warehouseName 仓库名称
     * @param brandName          品牌
     * @param snList        SN列表
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg advanceMachineCancelWarehouseNote(Integer userId, String userCode, String username, String warehouseName, String brandName, List<String> snList) {
        String title = "预发货拒绝通知";
        String summary = "创客："+userCode + username + "  已拒绝接收来自您的: "+warehouseName+"--"+brandName+", 的 "+snList.size()+" 台 预发货机具";

        StringBuilder content = new StringBuilder("<div class='16'>" + "创客：" + userCode + username + "  已拒绝接收来自您的: " + warehouseName + "--" + brandName + ", 的 " + snList.size() + " 台 预发货机具<br/>");
        for (String sn : snList) {
            content.append("<p class='16'>SN：").append(sn).append(",</p><br/>");
        }
        content.append("*注：请仔细核对SN后确认，确认接收机具后若出现机具丢失等问题，则需承担相应损失。");
        content.append("</div>");

        return MsgTemplateUtil.createHtmlMsg(userId, title, summary, content.toString());
    }

    /**
     * 预发货拒绝通知 用户
     *
     * @param userId             我
     * @param warehouseName 仓库名称
     * @param brandName     品牌
     * @param snList        SN列表
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg cancelAdvanceMachineUserNote(int userId, String warehouseName, String brandName, List<String> snList) {
        String title = "预发货拒绝通知";
        String summary = "已拒绝接收来自: "+warehouseName+"--"+ brandName + ", 的 "+snList.size()+" 台 预发货机具";

        StringBuilder content = new StringBuilder("<div class='16'>已拒绝接收来自: " + warehouseName + "--" + brandName + ", 的 " + snList.size() + " 台 预发货机具<br/>");
        for (String sn : snList) {
            content.append("<p class='16'>SN：").append(sn).append(",</p><br/>");
        }
        content.append("*注：请仔细核对SN后确认，确认接收机具后若出现机具丢失等问题，则需承担相应损失。");
        content.append("</div>");

        return MsgTemplateUtil.createHtmlMsg(userId, title, summary, content.toString());

    }

    /**
     * 创建 文本 消息
     *
     * @param userId  用户 ID
     * @param title   标题
     * @param content 内容
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg createTextMsg(Integer userId, String title ,String summary, String content){

        KxsUserMsg kxsUserMsg = new KxsUserMsg();
        kxsUserMsg.setUserId(userId);
        kxsUserMsg.setMsgType(2);
        kxsUserMsg.setTitle(title);
        kxsUserMsg.setContent(content);
        kxsUserMsg.setPushTime(LocalDateTime.now());
        return kxsUserMsg;
    }

    /**
     * 创建 html 消息
     *
     * @param userId  用户 ID
     * @param title   标题
     * @param content 内容
     * @return {@link KxsUserMsg}
     */
    public static KxsUserMsg createHtmlMsg(Integer userId, String title ,String summary, String content){

        KxsUserMsg kxsUserMsg = new KxsUserMsg();
        kxsUserMsg.setUserId(userId);
        kxsUserMsg.setMsgType(0);
        kxsUserMsg.setTitle(title);
        kxsUserMsg.setSummary(summary);
        kxsUserMsg.setContent(content);
        kxsUserMsg.setPushTime(LocalDateTime.now());
        return kxsUserMsg;
    }

}
