package org.jeecg.modules.api.carrentController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiService.ApplyService;
import org.jeecg.modules.carrentApply.entity.CarrentApply;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags="寻车申请相关接口")
@RestController
@RequestMapping("/api/apply")
@Slf4j
public class ApplyController {

    //寻车申请
    @Resource
    private ApplyService applyService;
    /******************************************************************************************************************/

    @ApiOperation(value="寻车申请-申请列表", notes="寻车申请-申请列表")
    @RequestMapping(value = "/queryApplyList", method = {RequestMethod.GET})
    public Result<?> queryApplyList(@RequestHeader("X-Access-Token") String token, PageBean pageBean){
        return applyService.queryApplyList(token, pageBean);
    }

    @ApiOperation(value="寻车申请-添加申请", notes="寻车申请-添加申请")
    @RequestMapping(value = "/addApply", method = {RequestMethod.GET})
    public Result<?> addApply(@RequestHeader("X-Access-Token") String token, CarrentApply carrentApply){

        String message = "";
        //申请信息验证
        if(StringUtils.isEmpty(carrentApply.getCategorytwoId())){
            message = "车辆分类id未填写，请填写车辆分类id";
        }else if(StringUtils.isEmpty(carrentApply.getModel())){
            message = "车辆型号未填写，请填写车辆型号";
        }else if(null == carrentApply.getCarTime() || "".equals(carrentApply.getCarTime())){
            message = "车辆年限未填写，请填写车辆年限";
        }else if(null == carrentApply.getMileage() || "".equals(carrentApply.getMileage())){
            message = "车辆公里数未填写，请填写车辆公里数";
        }else if(StringUtils.isEmpty(carrentApply.getName())){
            message = "联系人未填写，请填写联系人";
        }else if(StringUtils.isEmpty(carrentApply.getPhone())){
            message = "联系人电话未填写，填写联系人电话";
        }else {
            return applyService.addApply(token, carrentApply);
        }

        return Result.error(message);

    }

}
