package com.zanxiang.game.module.sdk.service.impl;

import com.zanxiang.game.module.base.ServerInfo;
import com.zanxiang.game.module.base.pojo.params.PushMsgParam;
import com.zanxiang.game.module.base.rpc.IPushMsgRpc;
import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
import com.zanxiang.game.module.sdk.pojo.param.GameUserRoleUpdateParam;
import com.zanxiang.game.module.sdk.pojo.param.UserData;
import com.zanxiang.game.module.sdk.service.IPushMsgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author : lingfeng
 * @time : 2024-05-28
 * @description : 消息推送
 */
@Slf4j
@Service
public class PushMsgServiceImpl implements IPushMsgService {

    @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
    private IPushMsgRpc pushMsgRpc;

    @Override
    public void pushMsgByRecharge(PlatformOrderDTO platformOrderDTO) {
        try {
            pushMsgRpc.pushMsgByRecharge(this.transform(platformOrderDTO));
        } catch (Exception ignored) {
        }
    }

    @Override
    public void pushMsgByLevelUpdate(GameUserRoleUpdateParam param, UserData userData) {
        try {
            pushMsgRpc.pushMsgByLevelUpdate(this.transform(param, userData));
        } catch (Exception ignored) {
        }
    }

    private PushMsgParam transform(PlatformOrderDTO platformOrderDTO) {
        return PushMsgParam.builder()
                .orderId(platformOrderDTO.getOrderId())
                .userId(platformOrderDTO.getUserId())
                .gameId(platformOrderDTO.getGameId())
                .serverId(platformOrderDTO.getServerId())
                .roleId(platformOrderDTO.getRoleId())
                .build();
    }

    private PushMsgParam transform(GameUserRoleUpdateParam param, UserData userData) {
        return PushMsgParam.builder()
                .userId(userData.getUserId())
                .gameId(userData.getGameId())
                .serverId(param.getServerId())
                .roleId(param.getRoleId())
                .roleLevel(param.getRoleLevel())
                .build();
    }
}
