
package com.tmerclub.cloud.multishop.feign;

import com.tmerclub.cloud.api.multishop.feign.ShopWalletLogFeignClient;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.multishop.constant.ShopWalletChangeReason;
import com.tmerclub.cloud.multishop.mongo.MongoShopWalletLogBO;
import com.tmerclub.cloud.multishop.service.ShopWalletLogService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

/**
 * @author chiley
 * @date 2022/6/30 16:55
 */
@DubboService
public class ShopWalletLogFeignController implements ShopWalletLogFeignClient {

    @Autowired
    private ShopWalletLogService shopWalletLogService;


    @Override
    public ServerResponseEntity<Long> getPayAmount(Long shopWalletLogId) {
        MongoShopWalletLogBO shopWalletLog = shopWalletLogService.getByWalletLogId(shopWalletLogId);
        return ServerResponseEntity.success(shopWalletLog.getShopChangeAmount());
    }

    @Override
    public ServerResponseEntity<Integer> getIsPay(Long shopWalletLogId) {
        MongoShopWalletLogBO shopWalletLog = shopWalletLogService.getByWalletLogId(shopWalletLogId);
        return ServerResponseEntity.success(Objects.equals(ShopWalletChangeReason.SUCCESS_RECHARGE.value(), shopWalletLog.getReason()) ? 1 : 0);
    }

    @Override
    public ServerResponseEntity<Integer> getShopBalancePayIsPay(Long orderId) {
        List<MongoShopWalletLogBO> mongoShopWalletLogList = shopWalletLogService.listByOrderIdAndReason(orderId, ShopWalletChangeReason.PURCHASE_SPREAD_AMOUNT.value());
        return ServerResponseEntity.success(CollectionUtils.isNotEmpty(mongoShopWalletLogList) ? 1 : 0);
    }

    @Override
    public ServerResponseEntity<Integer> getRefundShopBalancePayIsPay(Long orderId) {
        List<MongoShopWalletLogBO> mongoShopWalletLogList = shopWalletLogService.listByOrderIdAndReason(orderId, ShopWalletChangeReason.REFUND_SPREAD_AMOUNT.value());
        return ServerResponseEntity.success(CollectionUtils.isNotEmpty(mongoShopWalletLogList) ? 1 : 0);
    }

}
