package com.jeequan.jeepay.mgr.ctrl.merchant;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.ApiRes;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/mchApplyments")
public class LklspayMchApplymentController {

    /** 拉卡拉获取银行信息列表 **/
    @GetMapping("/getLklBankList/{areaCode}/{branchName}")
    public ApiRes getLklBankList(@PathVariable("areaCode") String areaCode, @PathVariable("branchName") String branchName) {
        HttpResponse httpResponse = null;
        try {
            String result = null;
            if (StringUtils.isNotEmpty(areaCode)) {
                httpResponse = HttpRequest.get("https://tkapi.lakala.com/registration/bank?areaCode=" + areaCode + "&bankName=" + branchName).execute();
                result = httpResponse.body();
            }
            return ApiRes.ok(result);
        } catch (Exception e) {
            throw new BizException(e.getMessage());
        } finally {
            if (httpResponse != null) {
                httpResponse.close();
            }
        }
    }
}
