package com.sonic.lion.service.impl;


import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.sonic.lion.service.CommonMessageService;
import com.sonic.pigeon.lib.client.MessageClient;
import com.sonic.pigeon.lib.enums.StationMessageTypeEnum;
import com.sonic.pigeon.lib.input.SendMessageInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 公共发送系统通知
 */
@Service
public class CommonMessageServiceImpl implements CommonMessageService {

    @Autowired
    private MessageClient messageClient;

    @Override
    public void memberRenewSuccess(Long userId, LocalDateTime expireTime) {
        String title = StationMessageTypeEnum.MEMBER_RENEW_SUCCESS.getTitle();
        String content = StationMessageTypeEnum.MEMBER_RENEW_SUCCESS.getContent();
        SendMessageInput sendMessageInput = new SendMessageInput(-1L, userId, StationMessageTypeEnum.MEMBER_RENEW_SUCCESS.getIndex(), title, content);
        Map<String, Object> extras = Maps.newHashMap();
        extras.put("expireTime", expireTime);
        sendMessageInput.setExtras(JSON.toJSONString(extras));
        messageClient.sendMessage(sendMessageInput);
    }

    @Override
    public void memberRenewFail(Long userId) {
        String title = StationMessageTypeEnum.MEMBER_RENEW_FAIL.getTitle();
        String content = StationMessageTypeEnum.MEMBER_RENEW_FAIL.getContent();
        SendMessageInput sendMessageInput = new SendMessageInput(-1L, userId, StationMessageTypeEnum.MEMBER_RENEW_FAIL.getIndex(), title, content);
        messageClient.sendMessage(sendMessageInput);
    }
}
