package com.bicloud.controller;


import com.bicloud.common.result.Result;
import com.bicloud.pojo.dto.RegisterDto;
import com.bicloud.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/user")
@Tag(name = "用户管理")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 发送手机验证码
     */
    @PostMapping("/code")
    @Operation(summary = "发送验证码")
    public Result sendCode(@RequestParam("mobile") String mobile, HttpSession session, HttpServletRequest request) {
        // 发送短信验证码并保存验证码
        return userService.sendCode(mobile, session, request);
    }

    /**
     * 用户注册
     */
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result register(@Valid @RequestBody RegisterDto registerDto) {
        return userService.register(registerDto);
    }

}
