package com.heyu.api.baidu.handle.common;


import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.constants.ApiConstants;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.common.BQrcodeReconizeRequest;
import com.heyu.api.baidu.response.common.BQrcodeReconizeResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 *
 */
@Component
@Slf4j
@CustomPath("qrCode")
public class BQrCodeHandle extends BaiduBaseHandle<BQrcodeReconizeRequest, BQrcodeReconizeResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/qrcode";
    }

    @Override
    public String check(BQrcodeReconizeRequest qrcodeReconizeRequest) {
        if (!ApiConstants.trueOrFalse.contains(qrcodeReconizeRequest.getLocation())) {
            return "location 仅能传：" + ApiConstants.trueOrFalse + ", 是否输出二维码/条形码位置信息.";
        }

        return checkOfd(qrcodeReconizeRequest);
    }

    @Override
    public String getContent(BQrcodeReconizeRequest qrcodeReconizeRequest) {
        StringBuffer sb = getOfdContent(qrcodeReconizeRequest);
        if (StringUtils.isNotBlank(qrcodeReconizeRequest.getLocation())) {
            sb.append("&location=" + qrcodeReconizeRequest.getLocation());
        }
        return sb.toString();
    }


}
