package com.xunhong.erp.turbo.facade.app.executor.cmd;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.xunhong.erp.turbo.api.facade.dto.vo.WxMaOcrIdCardVO;
import com.xunhong.erp.turbo.api.infra.api.SettingServiceI;
import com.xunhong.erp.turbo.facade.app.executor.common.WxCmdExe;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import me.chanjar.weixin.common.bean.ocr.WxOcrIdCardResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @author shenyifei
 */
@Component
@RequiredArgsConstructor
public class WxMaOcrIdCardCmdExe extends WxCmdExe {

	@DubboReference(version = "1.0.0")
	private final SettingServiceI settingService;

	@SneakyThrows
	public WxMaOcrIdCardVO execute(String ocrUrl) {
		WxMaService wxMaService = getWxMaService(settingService);
		WxOcrIdCardResult wxOcrIdCardResult = wxMaService.getOcrService().idCard(ocrUrl);
		String name = wxOcrIdCardResult.getName();
		String idCard = wxOcrIdCardResult.getId();
		WxMaOcrIdCardVO wxMaOcrIdCardVO = new WxMaOcrIdCardVO();
		wxMaOcrIdCardVO.setName(name);
		wxMaOcrIdCardVO.setIdCard(idCard);
		wxMaOcrIdCardVO.setOcrUrl(ocrUrl);
		return wxMaOcrIdCardVO;
	}
}
