package com.heyu.api.controller.doc;


import com.heyu.api.baidu.handle.doc.BRemoveHandwritingHandle;
import com.heyu.api.baidu.request.doc.BRemoveHandwritingRequest;
import com.heyu.api.baidu.response.doc.BRemoveHandwritingResp;
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.RemoveHandwritingResp;
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=1742718885645#/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=%2Frest%2F2.0%2Focr%2Fv1%2Fremove_handwriting&method=post
 *
 * 文档去手写
 *
 *
 * 接口描述
 * 去除图片中的手写内容，保留印刷体内容，可用于试卷去手写还原等场景。示意图如下：
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/doc")
@NotIntercept
public class RemoveHandwritingController extends BaseController {


    @Autowired
    private BRemoveHandwritingHandle bRemoveHandwritingHandle;

    @RequestMapping("/removeHandwriting")
    @CacheResult
    public R repair(BRemoveHandwritingRequest request) {

        RemoveHandwritingResp resp = new RemoveHandwritingResp();


        ApiR<BRemoveHandwritingResp> bR = bRemoveHandwritingHandle.handle(request);
        if (bR.isSuccess()) {

            BRemoveHandwritingResp bRemoveHandwritingResp = bR.getData();

            resp.setImageBase64(bRemoveHandwritingResp.getImageProcessed());
            resp.setPdfFileSize(bRemoveHandwritingResp.getPdfFileSize());


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


        }

        return R.error();
    }


}
