package com.heyu.api.controller.convert;

import com.heyu.api.baidu.handle.convert.BTextreviewHandle;
import com.heyu.api.baidu.handle.convert.BTextreviewQueryHandle;
import com.heyu.api.baidu.request.convert.BTextreviewQueryRequest;
import com.heyu.api.baidu.response.convert.BTextreviewQueryResp;
import com.heyu.api.baidu.response.convert.BTextreviewResp;
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.data.utils.StringUtils;
import com.heyu.api.request.convert.TextreviewReq;
import com.heyu.api.resp.convert.TextreviewRequestResp;
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;


@Slf4j
@RestController
@RequestMapping("/doc")
@NotIntercept
public class TextreviewController extends BaseController {

    @Autowired
    private BTextreviewHandle bTextreviewHandle;


    @Autowired
    private BTextreviewQueryHandle bTextreviewQueryHandle;


    @RequestMapping("/textreview")
    @CacheResult
    public R parse(TextreviewReq request) {


        if (StringUtils.isNotBlank(request.getTaskId())) {

            ApiR<BTextreviewResp> bR = bTextreviewHandle.handle(request);
            if (bR.isSuccess()) {
                TextreviewRequestResp resp = new TextreviewRequestResp();
                BTextreviewResp bTextreviewResp = bR.getData();

                resp.setTaskId(bTextreviewResp.getResult().getTaskId());

                return R.ok().setData(resp);
            }
            return R.error(bR.getErrorMsg());
        } else {

            BTextreviewQueryRequest bTextreviewQueryRequest = new BTextreviewQueryRequest();
            bTextreviewQueryRequest.setTaskId(request.getTaskId());


            ApiR<BTextreviewQueryResp> bR = bTextreviewQueryHandle.handle(bTextreviewQueryRequest);
            if(bR.isSuccess()   ){
                BTextreviewQueryResp bTextreviewQueryResp =     bR.getData();
                return R.ok().setData(bTextreviewQueryResp.getResult());
            }
            return R.error(bR.getErrorMsg());
        }
    }

}
