package top.continew.admin.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.common.context.UserExtraContext;
import top.continew.admin.user.model.req.AppLoginReq;
import top.continew.admin.user.service.AppLoginService;

@RestController()
@AllArgsConstructor
@Tag(name = "tg登录api")
@RequestMapping("/login")
@Slf4j
public class LoginController {
    private final AppLoginService loginService;

    @SaIgnore
    @GetMapping("/coinLogin")
    @Operation(summary = "tg账号登录", description = "根据tg用户id进行登录")
    public SaTokenInfo coinLogin(@Validated AppLoginReq req) {
        return loginService.tgLogin(req);
    }

    @RequestMapping("/getUserExtraContext")
    public UserExtraContext getUserExtraContext() {
        log.info("loginid {}", StpUtil.getLoginId());
        log.info(StpUtil.getLoginDevice());
        log.info("logintime {}", StpUtil.getExtra("loginTime"));
        UserExtraContext userExtraContext = new UserExtraContext();
        userExtraContext.setIp(StpUtil.getExtra("ip") + "");
        userExtraContext.setOs(StpUtil.getExtra("os") + "");
        return userExtraContext;
    }


}
