package com.yeejoin.amos.boot.module.jyjc.biz.message.open;

import com.yeejoin.amos.boot.module.jg.api.enums.WorkFlowStatusEnum;
import com.yeejoin.amos.boot.module.jyjc.biz.feign.MessageFeignClient;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * 系统对接中-消息处理器
 */
@Component
@RequiredArgsConstructor
public class OpenAppReceivePassMsgHandler implements IOpenApplicationMsgHandler {

    @Value("${open.app.msg.detail.path:/hyspm.html?appId=1742358052905971713&id=1947557820039720961&lfrom=studio}")
    private String msgDetailPath;

    private final MessageFeignClient messageFeignClient;

    @Override
    public String supportState() {
        return WorkFlowStatusEnum.OPENING_APPLICATION_PRELIMINARY.getPass();
    }

    @Override
    public void handle(String userId, String relationId, String companyType) {
        this.send(userId, relationId, companyType);
    }

    private void send(String userId, String relationId, String companyType) {
        MessageModel messageModel = new MessageModel();
        messageModel.setRecivers(Collections.singletonList(userId));
        messageModel.setMsgTypeLabel("检验检验业务开通");
        messageModel.setMsgType("openApp");
        messageModel.setTitle("系统对接");
        messageModel.setBody("资料校对已通过，请尽快按照消息详情提示进行系统对接！");
        messageModel.setRelationId(relationId + "1");
        messageModel.setTerminal("WEB");
        messageModel.setRoutePath(msgDetailPath + "&relationId=" + relationId);
        messageModel.setCompanyType(companyType);
        messageModel.setIsRead(false);
        messageModel.setIsSendWeb(true);
        messageFeignClient.create(messageModel);
    }
}
