package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.entity.Account;
import cn.pluss.platform.entity.MerchantChannelStatus;
import cn.pluss.platform.enums.ZfbChannel;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.AccountMapper;
import cn.pluss.platform.merchant.AccountService;
import cn.pluss.platform.merchantChannelStatus.MerchantChannelStatusService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lyf
 */
@RestController
@RequestMapping("/zxfAttestation")
public class ZfbAttestationController {
    @Resource
    private MerchantChannelStatusService merchantChannelStatusService;
    @Resource
    private AccountService accountService;
    @Resource
    private AccountMapper accountMapper;

    /**
     * 支付认证
     * @param params
     * @return
     */
    @PostMapping
    public Result<Object> Attestation(@RequestBody Map<String, String> params) {

        QueryWrapper<Account> QueryWrapper = new QueryWrapper<Account>()
                .eq("userId", Integer.valueOf(params.get("userId")))
                .eq("valid", 1);
        Account one = accountService.getOne(QueryWrapper);
        if (one == null){
            throw new MsgException("账号异常");
        }
        MerchantChannelStatus merchantCode = merchantChannelStatusService.getMerchantCodeByInfo(params.get("merchantCode"), one.getChannelType());
        HashMap<Object, Object> merchantCodeMap = new HashMap<>();
        switch (merchantCode.getChannel()){
            case 1:
                merchantCodeMap.put("virChannelFlag", merchantCode.getVirChannelFlag());
                merchantCodeMap.put("url", ZfbChannel.SXF_CHANNEL.getUrl());
                merchantCodeMap.put("nameChannel",ZfbChannel.SXF_CHANNEL.getName());
                break;
            case 4:
                merchantCodeMap.put("virChannelFlag", merchantCode.getVirChannelFlag());
                merchantCodeMap.put("url", ZfbChannel.YS_CHANNEL.getUrl());
                merchantCodeMap.put("nameChannel",ZfbChannel.YS_CHANNEL.getName());
                break;
            case 5:
                merchantCodeMap.put("virChannelFlag", merchantCode.getVirChannelFlag());
                merchantCodeMap.put("url", ZfbChannel.LKL_CHANNEL.getUrl());
                merchantCodeMap.put("nameChannel",ZfbChannel.LKL_CHANNEL.getName());
                break;
            case 6:
                merchantCodeMap.put("virChannelFlag", merchantCode.getVirChannelFlag());
                merchantCodeMap.put("url", ZfbChannel.YS_CHANNEL.getUrl());
                merchantCodeMap.put("nameChannel",ZfbChannel.YS_CHANNEL.getName());
                break;
            default:
                throw new MsgException("未知通道");
        }
        return ResultGenerator.genSuccessResult(merchantCodeMap);
    }
}
