package com.zhongzheng.controller.user;

import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.modules.user.bo.UserAppAccountLoginBo;
import com.zhongzheng.modules.user.bo.UserAppForgetBo;
import com.zhongzheng.modules.user.bo.UserAppRegisterBo;
import com.zhongzheng.modules.user.bo.UserAppSmsLoginBo;
import com.zhongzheng.modules.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 客户端用户Controller
 *
 * @author hjl
 * @date 2021-06-08
 */
@Api(value = "短信控制器", tags = {"登录控制器"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/app/common/")
public class LoginController extends BaseController {

    private final IUserService iUserService;

    /**
     * 用户注册
     */
    @ApiOperation("小程序用户注册")
    @PostMapping("/register_small")
    public AjaxResult<Void> register_small(@RequestBody UserAppRegisterBo bo) {
        return toAjax(iUserService.registerUser(bo) ? 1 : 0);
    }

    @ApiOperation("小程序忘记密码")
    @PostMapping("/register_forget")
    public AjaxResult<Void> register_forget(@RequestBody UserAppForgetBo bo) {
        return toAjax(iUserService.forgetUser(bo) ? 1 : 0);
    }

    @ApiOperation("短信登录")
    @PostMapping("/sms_login")
    public AjaxResult sms_login(@RequestBody UserAppSmsLoginBo bo) {
        Map<String,Object> map = iUserService.smsLogin(bo);
        return AjaxResult.success(map);
    }

    @ApiOperation("账号登录")
    @PostMapping("/account_login")
    public AjaxResult account_login(@RequestBody UserAppAccountLoginBo bo) {
        Map<String,Object> map = iUserService.accountLogin(bo);
        return AjaxResult.success(map);
    }
}
