package com.ankurm.authdemo.web;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @GetMapping("/public/status")
    public String publicEndpoint() {
        return "Public access - System Healthy";
    }

    @GetMapping("/user/dashboard")
    public String userDashboard() {
        return "User content - Visible to USER and ADMIN";
    }

    @GetMapping("/admin/panel")
    public String adminPanel() {
        return "Admin Content - RESTRICTED";
    }

    @GetMapping("/api/ping")
    public String apiPing() {
        return "pong from the JWT-protected API";
    }

    /** Debug helper: prints who the framework thinks you are. Delete before shipping. */
    @GetMapping("/whoami")
    public List<String> whoami(Authentication authentication) {
        return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).sorted().toList();
    }
}
