package com.liquidnet.service.dragon.channel.alipay.strategy.impl;

import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author AnJiabin <anjiabin@zhengzai.tv>
 * @version V1.0
 * @Description: TODO
 * @class: AlipayStrategyWapImpl
 * @Package com.liquidnet.service.dragon.channel.alipay.strategy.impl
 * @Copyright: LightNet @ Copyright (c) 2021
 * @date 2021/7/10 14:34
 */
@Slf4j
@Component
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.APP)
public class AlipayStrategyAppImpl extends AbstractAlipayStrategy {
    @Value("${liquidnet.dragon.url}")
    private String alipayGatewayUrl;

    @Value("${liquidnet.dragon.url}")
    private String notifyUrl;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Override
    protected Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq) {
        return AlipayUtil.tradeAppPay(alipayTradePayReq);
    }

    protected void setProductCode() {
        this.productCode = "QUICK_MSECURITY_PAY";
    }

    @Override
    protected String getNotifyUrl() {
        // notifyUrl = "/notify/app/alipay/1";
        return notifyUrl + "/app";
    }

    @Override
    DragonPayBaseRespDto buildResponseDto(DragonPayBaseRespDto payBaseRespDto, Map<String, Object> respResult) {
        payBaseRespDto.getPayData().setOrderStr(alipayGatewayUrl + "?" + respResult.get("body"));
        return payBaseRespDto;
    }
}
