package com.jeequan.jeepay.thirdparty.channel.ryxpay;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.interfaces.paychannel.IGetApplymentDataService;
import com.jeequan.jeepay.db.entity.BankBranch;
import com.jeequan.jeepay.service.impl.BankBranchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class RyxpayGetApplymentDataService implements IGetApplymentDataService {

    @Autowired
    private BankBranchService bankBranchService;

    /**
     * @cityCode 这里取城市名称.
     */
    @Override
    public List<JSONObject> getBankBranchInfo(String isvNo, String bankAliasCode, String cityCode, String bankName, String branchName) throws BizException {
//        Assert.notBlank(bankName, "银行名称不能为空");
        Page<BankBranch> page = new Page<>();
        bankBranchService.pageByArea(page, cityCode, bankName, branchName);

        return page.getRecords().stream().map( t -> ((JSONObject) JSON.toJSON(t))).collect(Collectors.toList());
    }
}
