package org.ta.authserver.controller;

import jakarta.annotation.Resource;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.ta.authserver.service.UserService;
import org.ta.commoncore.model.User;

import java.security.Principal;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Controller
//@RequestMapping("/user")
public class UserController {

//    @Resource
//    private UserService userService;
//
//    @GetMapping("/list")
//    public List<User> getUserList() {
//
//        return userService.list();
//    }
//
//    @PostMapping("/addUser")
//    public int addUser(@RequestBody User user){
//        return userService.addUser(user);
//    }

    @ResponseBody
    @GetMapping("/user")
    public Map<String,Object> user(Principal principal) {
        if (!(principal instanceof JwtAuthenticationToken)) {
            return Collections.emptyMap();
        }
        JwtAuthenticationToken token = (JwtAuthenticationToken) principal;
        return token.getToken().getClaims();
    }
}
