package com.tax.file.web.controller;


import com.tax.file.constants.FileConstants;
import com.tax.file.integration.user.UserClient;
import com.tax.file.model.*;
import com.tax.file.service.api.FIncomeInvoiceService;
import com.yxcheng.token.common.controller.BaseClientController;
import com.yxcheng.token.common.model.CrRpcResult;
import com.yxcheng.token.common.model.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/income")
public class IncomeController extends BaseClientController {

    @Autowired
    private UserClient userClient;

    @Autowired
    private FIncomeInvoiceService fIncomeInvoiceService;



    @RequestMapping(value ="/apply" , method = RequestMethod.POST)
    public JsonResult<List<InvoiceApplyRes>> apply(@RequestBody IncomeApplyReq incomeApplyReq){
        if(!FileConstants.isDebug()){
            CrRpcResult crRpcResult = userClient.isSafe(incomeApplyReq);
            if(!checkUserSafe(crRpcResult)){
                return JsonResult.errorResult(crRpcResult.getCode(),crRpcResult.getMessage());
            }
        }

        return fIncomeInvoiceService.apply(incomeApplyReq);
    }


    @RequestMapping(value ="/result" , method = RequestMethod.POST)
    public JsonResult<IncomeResultRes> result(@RequestBody IncomeResultReq incomeResultReq){
        if(!FileConstants.isDebug()){
            CrRpcResult crRpcResult = userClient.isSafe(incomeResultReq);
            if(!checkUserSafe(crRpcResult)){
                return JsonResult.errorResult(crRpcResult.getCode(),crRpcResult.getMessage());
            }
        }
        return fIncomeInvoiceService.result(incomeResultReq);
    }


    @RequestMapping(value ="/feedback" , method = RequestMethod.POST)
    public JsonResult<String> feedback(@RequestBody IncomeResultReq incomeResultReq){
        if(!FileConstants.isDebug()){
            CrRpcResult crRpcResult = userClient.isSafe(incomeResultReq);
            if(!checkUserSafe(crRpcResult)){
                return JsonResult.errorResult(crRpcResult.getCode(),crRpcResult.getMessage());
            }
        }
        return fIncomeInvoiceService.feedback(incomeResultReq);
    }


    @RequestMapping(value ="/query" , method = RequestMethod.POST)
    public JsonResult<IncomeQueryRes> query(@RequestBody IncomeQueryReq incomeQueryReq){
        if(!FileConstants.isDebug()){
            CrRpcResult crRpcResult = userClient.isSafe(incomeQueryReq);
            if(!checkUserSafe(crRpcResult)){
                return JsonResult.errorResult(crRpcResult.getCode(),crRpcResult.getMessage());
            }
        }

        return fIncomeInvoiceService.query(incomeQueryReq);
    }
}
