package shop.alien.gateway.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.dto.LifeUserPasswordDto;
import shop.alien.entity.store.vo.LifeUserVo;
import shop.alien.gateway.service.LifeUserPasswordService;

/**
 * 用户端密码登录（独立接口，不影响验证码登录）
 */
@Api(tags = {"一期-用户-密码登录"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/user/password")
@RequiredArgsConstructor
public class LifeUserPasswordController {

    private final LifeUserPasswordService lifeUserPasswordService;

    @ApiOperation("用户密码登录")
    @ApiOperationSupport(order = 1)
    @PostMapping("/login")
    public R<LifeUserVo> passwordLogin(@RequestBody LifeUserPasswordDto dto) {
        log.info("LifeUserPasswordController.passwordLogin?phoneNum={}", dto != null ? dto.getPhoneNum() : null);
        return lifeUserPasswordService.passwordLogin(dto);
    }

    @ApiOperation("忘记密码")
    @ApiOperationSupport(order = 2)
    @PostMapping("/forget")
    public R<String> forgetPassword(@RequestBody LifeUserPasswordDto dto) {
        log.info("LifeUserPasswordController.forgetPassword?phoneNum={}", dto != null ? dto.getPhoneNum() : null);
        return lifeUserPasswordService.forgetPassword(dto);
    }
}
