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

import com.zanxiang.game.module.base.rpc.IOrderServiceRpc;
import com.zanxiang.game.module.mybatis.entity.GameExt;
import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
import com.zanxiang.game.module.sdk.service.IGameExtService;
import com.zanxiang.game.module.sdk.service.IOrderService;
import com.zanxiang.game.module.sdk.service.IPerformOrderService;
import com.zanxiang.game.module.sdk.service.pay.MiPayService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

/**
 * @author : lingfeng
 * @time : 2023-07-27
 * @description : 游戏订单
 */
@DubboService
public class OrderServiceRpcImpl implements IOrderServiceRpc {

    @Autowired
    private IPerformOrderService performOrderService;

    @Resource
    private IOrderService orderService;

    @Autowired
    private IGameExtService gameExtService;

    @Autowired
    private MiPayService miPayService;

    @Override
    public boolean orderCpCall(String orderId, String payKey) {
        PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(orderId);
        GameExt gameExt = gameExtService.getByGameId(platformOrderDTO.getGameId());
        if (Objects.equals(gameExt.getPayKey(), payKey)) {
            return performOrderService.pushCp(platformOrderDTO);
        }
        return false;
    }

    @Override
    public Map<String, Object> miPayNotify(String orderId, String payKey) {
        PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(orderId);
        GameExt gameExt = gameExtService.getByGameId(platformOrderDTO.getGameId());
        if (Objects.equals(gameExt.getPayKey(), payKey)) {
            return miPayService.notify(orderId);
        }
        return Collections.emptyMap();
    }

}
