package com.heyu.api.controller.car;

import com.aliyun.ocr20191230.models.RecognizeTrainTicketResponse;
import com.aliyun.ocr20191230.models.RecognizeTrainTicketResponseBody;
import com.heyu.api.alibaba.handle.common.text.ARecognizeTrainTicketHandle;
import com.heyu.api.alibaba.request.common.text.ARecognizeTrainTicketRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.resp.car.RecognizeTrainTicketResp;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
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://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeTrainTicket?tab=DOC&lang=JAVA
 *
 * 火车票识别
 *
 * RecognizeTrainTicket
 *
 */
@Slf4j
@RestController
@RequestMapping("/train/ticket")
@NotIntercept
public class RecognizeTrainTicketController extends BaseController {


    @Autowired
    private ARecognizeTrainTicketHandle aRecognizeTrainTicketHandle;


    @RequestMapping("/recognize")
    public R recognize(ARecognizeTrainTicketRequest request) {
        ApiR<RecognizeTrainTicketResponse> aR = aRecognizeTrainTicketHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            RecognizeTrainTicketResponse recognizeTrainTicketResponse = aR.getData();

            RecognizeTrainTicketResponseBody responseBody = recognizeTrainTicketResponse.getBody();
            RecognizeTrainTicketResponseBody.RecognizeTrainTicketResponseBodyData responseBodyData = responseBody.getData();

            RecognizeTrainTicketResp resp = new RecognizeTrainTicketResp();
            resp.setPrice(responseBodyData.getPrice());
            resp.setDestination(responseBodyData.getDestination());
            resp.setDepartureStation(responseBodyData.getDepartureStation());
            resp.setDate(responseBodyData.getDate());
            resp.setNumber(responseBodyData.getNumber());
            resp.setSeat(responseBodyData.getSeat());
            resp.setName(responseBodyData.getName());
            resp.setLevel(responseBodyData.getLevel());
            return R.ok().setData(resp);
        }
        return R.error();
    }
}
