package com.heyu.api.controller.others;

import com.heyu.api.baidu.handle.others.BFacadeHandle;
import com.heyu.api.baidu.request.others.BFacadeRequest;
import com.heyu.api.baidu.response.others.BFacadeResp;
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.others.FacadeResp;
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;

import java.util.ArrayList;
import java.util.List;



/***
 * https://console.bce.baidu.com/support/?_=1740667714316&timestamp=1740669989457#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%85%B6%E4%BB%96%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Ffacade&method=post
 *
 * 门脸文字识别
 *
 *
 * 接口描述
 * 针对含有门脸/门头的图片进行专项优化，支持识别门脸/门头上的文字内容。
 */
@Slf4j
@RestController
@RequestMapping("/facade")
@NotIntercept
public class FacadeController extends BaseController {


    @Autowired
    private BFacadeHandle bFacadeHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BFacadeRequest request) {
        List<FacadeResp> respList = new ArrayList<>();

        ApiR<BFacadeResp> bR = bFacadeHandle.handle(request);
        if (bR.isSuccess()) {
            BFacadeResp bFacadeResp = bR.getData();
            List<BFacadeResp.WordsResultDTO> wordsResultDTOS = bFacadeResp.getWordsResult();

            for (BFacadeResp.WordsResultDTO wordsResultDTO : wordsResultDTOS) {

                FacadeResp facadeResp = new FacadeResp();
                facadeResp.setWords(wordsResultDTO.getWords());
                facadeResp.setBrief(wordsResultDTO.getBrief());
                facadeResp.setWords(wordsResultDTO.getWords());
                respList.add(facadeResp);
            }

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

        }
        return R.error(bR.getErrorMsg());
    }


}
