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.UserBean;
import org.jeecg.modules.apiService.UserService;
import org.jeecg.modules.carrentUser.entity.CarrentUser;
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/user")
@Slf4j
public class UserController {

    //预约信息
    @Resource
    private UserService userService;
    /****************************************************************************************************/

    @ApiOperation(value="用户信息-个人注册", notes="用户信息-个人注册")
    @RequestMapping(value = "/addUser", method = {RequestMethod.POST})
    public Result<?> addUser(@RequestHeader("X-Access-Token") String token, UserBean userBean){

        //将注册信息注入到实体bean中
        CarrentUser carrentUser = new CarrentUser();
        carrentUser.setName(userBean.getName());
        carrentUser.setCerNo(userBean.getCerNo());
        carrentUser.setPhone(userBean.getPhone());
        carrentUser.setCerImage(userBean.getCerImage());

        String message = "";
        //注册信息验证
        if(StringUtils.isEmpty(carrentUser.getName())){
            message = "用户姓名未填写，请填写用户姓名!";
        }else if(StringUtils.isEmpty(carrentUser.getCerNo())){
            message = "身份证号码未填写，请填写身份证号码!";
        }else if(StringUtils.isEmpty(carrentUser.getPhone())){
            message = "联系方式未填写，请填写联系方式!";
        }else if(StringUtils.isEmpty(carrentUser.getCerImage())){
            message = "身份证正面照片未填写，请上传身份证正面照片!";
        }else {
            //注册信息无误，进入业务流程处理
            return userService.addUser(token, carrentUser);
        }

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

    /*****************************************************************************************************************/
    //查看个人信息

    @ApiOperation(value="用户信息-查看个人信息", notes="用户信息-查看个人信息")
    @RequestMapping(value = "/queryUser", method = {RequestMethod.GET})
    public Result<?> queryUser(@RequestHeader("X-Access-Token") String token){
        return userService.queryUserInfo(token);
    }

    //lzx：修改个人信息
    @ApiOperation(value="用户信息-修改个人信息", notes="用户信息-修改个人信息")
    @RequestMapping(value = "/updateUser", method = {RequestMethod.POST})
    public Result<?> updateUser(@RequestHeader("X-Access-Token") String token,String nickName,String phone,String headImage){
        return userService.updateUserInfo(token, nickName, phone, headImage);
    }

}
