package com.rera.mss.controller

import com.rera.mss.payload.JwtAuthenticationResponse
import com.rera.mss.payload.UserSummary
import com.rera.mss.security.CurrentUser
import com.rera.mss.security.UserPrincipal
import org.apache.catalina.User
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api")
class UserController {
    @GetMapping("/user/me")
    @PreAuthorize("hasRole('USER')")
    fun getCurrentUser(@CurrentUser currentUser: UserPrincipal): ResponseEntity<UserSummary> {
        val userSummary = UserSummary(currentUser.getId(), currentUser.username, currentUser.getFirstName())
        return ResponseEntity.ok(userSummary)
    }
}