package cn.qinys.platform.mobile.controller;

import cn.qinys.platform.base.response.Result;
import cn.qinys.platform.mobile.req.LoginReq;
import cn.qinys.platform.mobile.resp.CaptchaResp;
import cn.qinys.platform.mobile.resp.LoginResp;
import cn.qinys.platform.mobile.resp.UserWishSummaryResp;
import cn.qinys.platform.mobile.service.LoginService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author lie tan
 * @description
 * @date 2026-06-06 13:14
 **/

@Slf4j
@RestController
@RequestMapping("/dgapi/mobile/user")
public class UserController {

    @Resource
    LoginService loginService;


    /**
     * 获取验证码
     *
     * @return
     */
    @GetMapping("/login/captcha")
    public Result<CaptchaResp> getCaptcha(@RequestParam(name = "type",required = false, defaultValue = "1") String type) {
        CaptchaResp captcha = loginService.getCaptcha(type);
        return new Result<>(captcha);
    }


    /**
     * 登录
     *
     * @param req
     * @return
     */
    // @SensitiveRequest
    @PostMapping("/login")
    public Result<LoginResp> login(@RequestBody @Valid LoginReq req) {
        LoginResp res = loginService.login(req);
        return new Result<>(res);
    }

    @PostMapping("/logout")
    public Result<LoginResp> logout() {
        loginService.logout();
        return new Result<>("success");
    }


    @PostMapping("/wish/summary")
    public Result<UserWishSummaryResp> wishSummary() {
        UserWishSummaryResp resp = loginService.wishSummary();
        return new Result<>(resp);
    }


}
