package com.community.huiju.controller;


import com.community.huiju.common.base.BaseController;
import com.community.huiju.common.base.ResponseBean;
import com.community.huiju.service.ITaUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 住户app端用户表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-05-15
 */
@RestController
@RequestMapping("/")
@Api(value = "用户操作 API", description = "用户操作 API")
public class TaUserController extends BaseController {

    @Autowired
    private ITaUserService iTaUserService;


    @RequestMapping(value = "/user", method = RequestMethod.POST)
    @ApiOperation(value = "添加用户", notes = "添加用户")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "userName", value = "用户名"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "idCard", value = "身份证"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "gender", value = "性别 1：男   2：女"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "phone", value = "手机号"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "appid", value = "appid"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "datetime", value = "时间戳"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "encrypt", value = "加密方式"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "sign", value = "签名"),
    })
    public ResponseBean addUser(@RequestParam(value = "userName") String userName,
                                @RequestParam(value = "idCard") String idCard,
                                @RequestParam(value = "gender") String gender,
                                @RequestParam(value = "phone") String phone){
        ResponseBean responseBean = iTaUserService.addTaUser(userName, idCard, gender, phone);
        return responseBean;
    }

    @RequestMapping(value = "/user/{userId}", method = RequestMethod.PUT)
    @ApiOperation(value = "修改用户", notes = "修改用户")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "path", name = "userId", value = "用户id"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "userName", value = "用户名"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "idCard", value = "身份证"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "gender", value = "性别 1：男   2：女"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "phone", value = "手机号"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "appid", value = "appid"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "datetime", value = "时间戳"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "encrypt", value = "加密方式"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "form", name = "sign", value = "签名"),
    })
    public ResponseBean updateUser(@PathVariable(value = "userId") Integer userId,
                                @RequestParam(value = "userName", required = false) String userName,
                                @RequestParam(value = "idCard", required = false) String idCard,
                                @RequestParam(value = "gender", required = false) String gender,
                                @RequestParam(value = "phone", required = false) String phone){
        ResponseBean responseBean = iTaUserService.updateTaUser(userId,userName, idCard, gender, phone);
        return responseBean;
    }

    @RequestMapping(value = "/user/{userId}", method = RequestMethod.GET)
    @ApiOperation(value = "根据用户ID查询", notes = "根据用户ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "path", name = "userId", value = "用户id"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "appid", value = "appid"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "datetime", value = "时间戳"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "encrypt", value = "加密方式"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "sign", value = "签名"),
    })
    public ResponseBean updateUser(@PathVariable(value = "userId") Integer userId){
        ResponseBean responseBean = iTaUserService.getTaUser(userId);
        return responseBean;
    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    @ApiOperation(value = "根据用户手机号查询", notes = "根据用户手机号查询")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "phone", value = "手机号"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "appid", value = "appid"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "datetime", value = "时间戳"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "encrypt", value = "加密方式"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "sign", value = "签名"),
    })
    public ResponseBean updateUser(@RequestParam(value = "phone") String phone){
        ResponseBean responseBean = iTaUserService.getTaUserByPhone(phone);
        return responseBean;
    }

}
