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.OrderService;
import org.jeecg.modules.carrentOrder.entity.CarrentOrder;
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/order")
@Slf4j
public class OrderController {

    //预约信息
    @Resource
    private OrderService orderService;
    /****************************************************************************************************/

    @ApiOperation(value="车辆预约-车辆预约列表", notes="车辆预约-车辆预约列表")
    @RequestMapping(value = "/queryOrderList", method = {RequestMethod.GET})
    public Result<?> queryOrderList(@RequestHeader("X-Access-Token") String token, String typeId, PageBean pageBean){
        return orderService.queryOrderList(token, typeId, pageBean);
    }

    @ApiOperation(value="车辆预约-提交预约信息", notes="车辆预约-提交预约信息")
    @RequestMapping(value = "/addOrder", method = {RequestMethod.POST})
    public Result<?> addOrder(@RequestHeader("X-Access-Token") String token, CarrentOrder carrentOrder){

        String message = "";
        //预约信息验证
        if(StringUtils.isEmpty(carrentOrder.getName())){
            message = "联系人姓名未填写，请填写联系人姓名";
        }else if(StringUtils.isEmpty(carrentOrder.getPhone())){
            message = "联系人手机号未填写，请填写联系人手机号";
        }else if(StringUtils.isEmpty(carrentOrder.getGoodsId())){
            message = "预约商品id未填写，请填写预约商品id";
        }else {
            //预约信息无误，进入业务流程处理
            return orderService.addOrder(token, carrentOrder);
        }

        //预约信息有误，返回错误信息
        return Result.error(message);
    }

}
