package com.hc.web.controller.browser.front;

import com.hc.business.dto.ZccmRetrievePasswordDto;
import com.hc.business.dto.ZccmSmsLoginDto;
import com.hc.business.model.ZccmUser;
import com.hc.business.model.login.AuthEntity;
import com.hc.business.service.ZccmUserService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;


import javax.validation.Valid;


/**
 * 用户表(ZccmUser)表控制层
 *
 * @author java
 * @since 2020-11-09 10:04:14
 */

@RestController
@RequestMapping("/new/api/front/user")
public class FrontUserController {

    /**
     * 服务对象
     */
    private final ZccmUserService userService;

    public FrontUserController(ZccmUserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 ZccmUser", response = Result.class)
    public Result selectFrontDetail(@PathVariable("id") Integer id) {
        return Result.success(this.userService.queryById(id));
    }

    @PostMapping("/login")
    @ApiOperation(value = "用户登录(账号,密码)", response = Result.class)
    public Result userLogin(@RequestBody AuthEntity authEntity) {
        return Result.success(userService.userLogin(authEntity));
    }

    @PostMapping("/login/sms")
    @ApiOperation(value = "用户登录(短信登录)", response = Result.class)
    public Result userLoginSms(@Valid @RequestBody ZccmSmsLoginDto zccmSmsLoginDto) {
        return Result.success(userService.userLoginSms(zccmSmsLoginDto));
    }

    @PostMapping("/register")
    @ApiOperation(value = "用户注册", response = Result.class)
    public Result userRegister(@Valid @RequestBody ZccmRetrievePasswordDto zccmRetrievePasswordDto) {
        return Result.success(userService.userRegister(zccmRetrievePasswordDto));
    }

    @PostMapping("/send")
    @ApiOperation(value = "短信发送验证码", response = Result.class)
    public Result sendAuthCode(@ApiParam(value = "手机号") @RequestParam String userMobile) {
        return Result.success(userService.sendAuthCode(userMobile));
    }

    @GetMapping("/mobile")
    @ApiOperation(value = "依据手机号查询用户", response = Result.class)
    public Result queryByMobile(@ApiParam(value = "手机号") @RequestParam String userMobile) {
        return Result.success(userService.queryByMobile(userMobile));
    }

    @PostMapping("/retrievePassword")
    @ApiOperation(value = "找回密码", response = Result.class)
    public Result retrievePassword(@Valid @RequestBody ZccmRetrievePasswordDto zccmRetrievePasswordDto) {
        return Result.success(userService.retrievePassword(zccmRetrievePasswordDto));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmUser", response = Result.class)
    public Result addZccmUser(@Valid @RequestBody ZccmUser user) {
        return Result.success(userService.insert(user));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmUser", response = Result.class)
    public Result updateZccmUser(@RequestBody ZccmUser user) {
        return Result.success(userService.update(user));
    }

}