package org.springblade.modules.app.web;

import com.wn.common.controller.BaseController;
import com.wn.common.datamodel.ResultDTO;
import com.wn.common.validator.Validator;
import org.springblade.modules.app.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.auth.permission.DisableLoginVerify;
import org.springblade.modules.app.constant.ErrorCode;
import org.springblade.modules.app.manager.ImageRecognitionManager;
import org.springblade.modules.app.service.IOcrService;
import org.springblade.modules.app.vo.OcrRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("app/ocr")
@Api(value = "图像识别", tags = "图像识别")
public class ImageRecognitionController extends BaseController {

    @Autowired
    ImageRecognitionManager imageRecognitionManager;

    @Autowired
    private IOcrService ocrService;

    @ResponseBody
    @PostMapping("/businessLicense")
    //@ApiOperation(value = "营业执照识别")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<BusinessLicenseDTO>> getBusinessLicenseInfo(@RequestBody OcrRequestVO requestVO){
        Validator.notNull(requestVO, ErrorCode.PARAM_DATA_NULL);
        return success(imageRecognitionManager.getBusinessLicenseInfo(requestVO.getUrl()));
    }

    @ResponseBody
    @PostMapping("/identityCard")
    //@ApiOperation(value = "身份证识别")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<IdentityCardDTO>> getIDInfo(@RequestBody OcrRequestVO requestVO){
        Validator.notNull(requestVO, ErrorCode.PARAM_DATA_NULL);
        return success(ocrService.recognizeIdcard(requestVO.getUrl()));
    }

    @ResponseBody
    @PostMapping("/driverLicense")
    //@ApiOperation(value = "驾驶证识别")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<DriverDTO>> getDriverInfo(@RequestBody OcrRequestVO requestVO){
        Validator.notNull(requestVO, ErrorCode.PARAM_DATA_NULL);
        return success(imageRecognitionManager.getDriverInfo(requestVO.getUrl()));
    }

    @ResponseBody
    @PostMapping("/drivingLicense")
    //@ApiOperation(value = "行驶证识别")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<DrivingDTO>> getDrivingInfo(@RequestBody OcrRequestVO requestVO){
        Validator.notNull(requestVO, ErrorCode.PARAM_DATA_NULL);
        return success(imageRecognitionManager.getDrivingInfo(requestVO.getUrl()));
    }

    @ResponseBody
    @PostMapping("/common")
    //@ApiOperation(value = "通用识别")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<String>> getCurrencyInfo(@RequestBody OcrRequestVO requestVO){
        Validator.notNull(requestVO, ErrorCode.PARAM_DATA_NULL);
        return success(imageRecognitionManager.getCurrencyInfo(requestVO.getUrl()));
    }

    @ResponseBody
    @PostMapping("/common/withResult")
    //@ApiOperation(value = "通用识别带返回值")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<CommonDTO>> getCommonInfoWithResult(@RequestBody OcrRequestVO requestVO){
        Validator.notNull(requestVO, ErrorCode.PARAM_DATA_NULL);
        return success(imageRecognitionManager.getCommonInfoWithResult(requestVO.getUrl()));
    }
}
