package com.heyu.api.controller.others;

import com.heyu.api.baidu.handle.others.BMeterHandle;
import com.heyu.api.baidu.request.others.BMeterRequest;
import com.heyu.api.baidu.response.others.BMeterResp;
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.MeterResp;
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=1740667716472#/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%2Fmeter&method=post
 *
 * 仪器仪表盘读数识别
 *
 *
 *接口描述
 * 适用于不同品牌、不同型号的仪器仪表盘读数识别，广泛适用于各类血糖仪、血压仪、燃气表、电表等，可识别表盘上的数字、英文、符号，支持液晶屏、字轮表等表型。
 *
 */
@Slf4j
@RestController
@RequestMapping("/meter")
@NotIntercept
public class MeterController extends BaseController {


    @Autowired
    private BMeterHandle bMeterHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BMeterRequest request) {

        List<MeterResp> meterResp = new ArrayList<>();

        ApiR<BMeterResp> bR = bMeterHandle.handle(request);
        if (bR.isSuccess()) {
            BMeterResp bMeterResp = bR.getData();
            List<BMeterResp.WordsResultDTO> wordsResult = bMeterResp.getWordsResult();

            for (BMeterResp.WordsResultDTO wordsResultDTO : wordsResult) {

                MeterResp meterResp1 = new MeterResp();
                meterResp1.setWords(wordsResultDTO.getWords());


                meterResp.add(meterResp1);

            }
            return R.ok().setData(meterResp);

        }

        return R.error();
    }
}
