package com.jkcredit.invoice.controller.service;

import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeModel;
import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
import com.jkcredit.invoice.service.lowerService.SelfCarServiceL;
import com.jkcredit.invoice.service.lowerService.vo.*;
import com.jkcredit.invoice.util.RespR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "自有车下游接口")
@RestController
@RequestMapping(value = {"/selfCarService"})
public class SelfCarServiceController {
    @Autowired
    SelfCarServiceL selfCarService;
    /**
     * @param tradeRequestVo
     * @return
     */
    @PostMapping("/getTradeList")
    @ApiOperation(value="获取交易Id列表", notes="获取交易Id列表")
    //@LoginRequired
    public RespR getTradeList(@RequestBody TradeRequestVo tradeRequestVo){
        if(tradeRequestVo.getTradeStatus() ==null){
            tradeRequestVo.setTradeStatus(1);
            RespR<List<CardTradeModel>> respRbefore = selfCarService.getTradeList(tradeRequestVo);
            tradeRequestVo.setTradeStatus(2);
            RespR<List<CardTradeModel>> respRUnder = selfCarService.getTradeList(tradeRequestVo);
            tradeRequestVo.setTradeStatus(3);
            RespR<List<CardTradeModel>> respRAfter = selfCarService.getTradeList(tradeRequestVo);
            //合并展示
            List<CardTradeModel> cardTradeModels = new ArrayList<>();
            if(respRbefore.getCode() == 0){
                cardTradeModels.addAll(respRbefore.getData());
            }
            if(respRUnder.getCode() == 0){
                cardTradeModels.addAll(respRUnder.getData());
            }
            if(respRAfter.getCode() == 0){
                cardTradeModels.addAll(respRAfter.getData());
            }
            return new RespR(cardTradeModels);
        }
        //合并展示

        return selfCarService.getTradeList(tradeRequestVo);
    }

    /**
     * @param invoiceApplVo
     * @return
     */
    @PostMapping("/applInvoice")
    @ApiOperation(value="开票申请", notes="开票申请")
    //@LoginRequired
    public RespR applInvoice(@RequestBody InvoiceApplVo invoiceApplVo){
        return selfCarService.applInvoice(invoiceApplVo);
    }

    /**
     * @param selfCarDueQueryVo
     * @return
     */
    @PostMapping("/getSelfCarInvoicesByTime")
    @ApiOperation(value="已开发票查询", notes="已开发票查询")
    //@LoginRequired
    public RespR getSelfCarInvoicesByTime(@RequestBody SelfCarDueQueryVo selfCarDueQueryVo){
        return selfCarService.getSelfCarInvoicesByTime(selfCarDueQueryVo);
    }

    /**
     * @param ApplQueryInvVo
     * @return
     */
    @PostMapping("/getSelfCarInvoicesByAppl")
    @ApiOperation(value="按申请id查询发票", notes="按申请id查询发票")
    //@LoginRequired
    public RespR getSelfCarInvoicesByAppl(@RequestBody ApplQueryInvVo ApplQueryInvVo){
        return selfCarService.getSelfCarInvoicesByApplyIds(ApplQueryInvVo);
    }
    /**
     * @param etcQueryVo
     * @return
     */
    @PostMapping("/customerETCQuery")
    @ApiOperation(value="", notes="ETC查询")
    //@LoginRequired
    public RespR customerETCQuery(@RequestBody EtcQueryVo etcQueryVo){
        return selfCarService.getEtcInfo(etcQueryVo);
    }
    /**
     * @param etcBindVo
     * @return
     */
    @PostMapping("/customerETCRec")
    @ApiOperation(value="", notes="ETC备案")
    //@LoginRequired
    public RespR customerETCRec(@RequestBody EtcBindVo etcBindVo){
        return selfCarService.customerEtcRec(etcBindVo);
    }


    /**
     * @param etcValidVo
     * @return
     */
    @PostMapping("/customerETCRecValid")
    @ApiOperation(value="", notes="ETC备案验证")
    //@LoginRequired
    public RespR customerETCRecValid(@RequestBody EtcValidVo etcValidVo){
        return selfCarService.customerEtcRecValid(etcValidVo);
    }

    /**
     * @param customerCarRecs
     * @return
     */
    @PostMapping("/customerCarUnRec")
    @ApiOperation(value="", notes="etc解绑")
    //@LoginRequired
    public RespR customerCarUnRec(@RequestBody List<CustomerCarRec> customerCarRecs){
        return selfCarService.customerCarUnRec(customerCarRecs);
    }
}
