package de.avatic.lcc.controller.users;

import de.avatic.lcc.dto.users.UserDTO;
import de.avatic.lcc.repositories.users.UserRepository;
import de.avatic.lcc.service.transformer.users.UserTransformer;
import de.avatic.lcc.service.users.AuthorizationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/api/active-user", "/api/active-user/"})
public class ActiveUserController {


    private final AuthorizationService authorizationService;

    public ActiveUserController(AuthorizationService authorizationService) {
        this.authorizationService = authorizationService;
    }

    @GetMapping
    public ResponseEntity<UserDTO> getActiveUser() {
        var user = authorizationService.getActiveUser();
        if (user != null) return ResponseEntity.ok(user);
        return ResponseEntity.internalServerError().build();
    }
}
