package com.heyu.api.controller.doc;


import com.heyu.api.baidu.handle.doc.BDocCropEnhanceHandle;
import com.heyu.api.baidu.request.doc.BDocCropEnhanceRequest;
import com.heyu.api.baidu.response.others.BDocCropEnhanceResp;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.doc.DocCropEnhanceResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * https://console.bce.baidu.com/support/?_=1740667714316&timestamp=1742718224202#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E6%96%87%E6%A1%A3%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86&api=rest%2F2.0%2Focr%2Fv1%2Fdoc_crop_enhance&method=post
 *
 *文档矫正增强
 *
 *
 * 接口描述
 * 对图片中的文件、卡证、票据等内容进行四角点检测定位，提取主体内容并对其进行矫正，同时可选图片增强效果进一步提升图片清晰度，达到主体检测矫正并增强的目的，提升图片整体质量。示意图如下：
 *
 */
@Slf4j
@RestController
@RequestMapping("/doc")
@NotIntercept
public class DocCropEnhanceController extends BaseController {

    @Autowired
    private BDocCropEnhanceHandle bDocCropEnhanceHandle;

    @RequestMapping("/cropEnhance")
    @CacheResult
    public R cropEnhance(BDocCropEnhanceRequest request) {
        DocCropEnhanceResp resp = new DocCropEnhanceResp();

        ApiR<BDocCropEnhanceResp> bR = bDocCropEnhanceHandle.handle(request);


        if (bR.isSuccess()) {
            BDocCropEnhanceResp bDocCropEnhanceResp = bR.getData();

            resp.setImageProcessed(bDocCropEnhanceResp.getImageProcessed());
            resp.setPdfFileSize(bDocCropEnhanceResp.getPdfFileNum() + "");

            return R.ok().setData(resp);

        }

        return R.error();
    }
}
