package com.cool.store.controller.webb;

import com.cool.store.dto.login.UserLoginDTO;
import com.cool.store.dto.login.UserRefreshLoginDTO;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.login.LoginBaseService;
import com.cool.store.service.login.LoginStrategy;
import com.cool.store.utils.SpringContextUtil;
import com.cool.store.vo.login.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 登录 前端控制器
 * </p>
 *
 * @author wangff
 * @since 2025/9/4
 */
@Api(tags = "登录")
@RestController
@RequestMapping("/pc/v3/login")
@RequiredArgsConstructor
public class LoginController {
    private final LoginBaseService loginBaseService;

    @ApiOperation("账号密码登录")
    @PostMapping("/accountLogin")
    public ResponseResult<UserLoginVO> accountLogin(@RequestBody UserLoginDTO param) {
        return SpringContextUtil.getBean(param.getLoginType().getClazzName(), LoginStrategy.class).login(param);
    }

    @ApiOperation("refresh登录")
    @PostMapping("/refreshLogin")
    public ResponseResult<UserLoginVO> refreshLogin(@RequestBody UserRefreshLoginDTO param) {
        return loginBaseService.refreshLogin(param);
    }

    @ApiOperation("登出")
    @PostMapping("/logout")
    public ResponseResult logout() {
        return loginBaseService.logout();
    }
}
