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.GoodsService;
import org.jeecg.modules.carrentGoods.entity.CarrentGoods;
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/goods")
@Slf4j
public class GoodsController {

    //商品信息
    @Resource
    private GoodsService goodsService;
    /****************************************************************************************************/

    @ApiOperation(value="商品信息-获取商品列表", notes="商品信息-获取商品列表")
    @RequestMapping(value = "/queryGoodsList", method = {RequestMethod.GET})
    public Result<?> queryGoodsList(String token, CarrentGoods goods, PageBean pageBean){
        return goodsService.queryGoodsList(token, goods, pageBean);
    }

    @ApiOperation(value="商品信息-根据id获取商品详情", notes="商品信息-根据id获取商品详情")
    @RequestMapping(value = "/queryGoodsById", method = {RequestMethod.GET})
    public Result<?> queryGoodsById(String goodsId){
        return goodsService.queryGoodsById(goodsId);
    }

    @ApiOperation(value="商品信息-车辆信息发布", notes="商品信息-车辆信息发布")
    @RequestMapping(value = "/addGoods", method = {RequestMethod.POST})
    public Result<?> addGoods(@RequestHeader("X-Access-Token") String token, CarrentGoods goods){

        String message = "";
        //车辆发布信息验证
        if(StringUtils.isEmpty(goods.getCartypeId())){
            message = "车辆类型id未填写，请填写车辆类型id";
        }else if(StringUtils.isEmpty(goods.getCategorytwoId())){
            message = "车辆分类id未填写，请填写车辆分类id";
        }else if(StringUtils.isEmpty(goods.getGoodsName())){
            message = "车辆名称未填写，请填写车辆名称";
        }else if(StringUtils.isEmpty(goods.getArea())){
            message = "区域未填写，请填写区域";
        }else if(null == goods.getGoodsTime() || "".equals(goods.getGoodsTime())){
            message = "车辆生产时间未填写，请填写车辆生产时间";
        }else if(null == goods.getMileage() || "".equals(goods.getMileage())){
            message = "车辆公里数未填写，请填写车辆公里数";
        }else if(null == goods.getPrice() || "".equals(goods.getPrice())){
            message = "车辆价格未填写，请填写车辆价格";
        }else if(StringUtils.isEmpty(goods.getUserName())){
            message = "联系人未填写，请填写联系人";
        }else if(StringUtils.isEmpty(goods.getPhone())){
            message = "联系人电话未填写，请填写联系人电话";
        }else if(StringUtils.isEmpty(goods.getImageFront())){
            message = "车辆照片(前)未上传，请上传车辆照片(前)";
        }else if(StringUtils.isEmpty(goods.getImageBack())){
            message = "车辆照片(后)未上传，请上传车辆照片(后)";
        }else if(StringUtils.isEmpty(goods.getImageLeft())){
            message = "车辆照片(左)未上传，请上传车辆照片(左)";
        }else if(StringUtils.isEmpty(goods.getImageRight())){
            message = "车辆照片(右)未上传，请上传车辆照片(右)";
        }else if(StringUtils.isEmpty(goods.getImageCab())){
            message = "车辆照片(驾驶室)未上传，请上传车辆照片(驾驶室)";
        }else {
            return goodsService.addGoods(token, goods);
        }

        return Result.error(message);
    }

}
