package com.spring.domain.user.api;

import java.util.List;

import javax.validation.Valid;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.spring.domain.user.dto.ChangeUserRoleApproveRequest;
import com.spring.domain.user.dto.UserFindRequest;
import com.spring.domain.user.dto.UserManagementResponse;
import com.spring.domain.user.service.UserManagementService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user")
public class UserManagementApi {
    
    private final UserManagementService userManagementService;

    @GetMapping
    @PreAuthorize("hasAnyRole('SUPER')")
    public List<UserManagementResponse> getUsers(UserFindRequest request) {
        return userManagementService.getUsers(request);
    }

    @PutMapping("/change-role-approve")
    @PreAuthorize("hasAnyRole('SUPER')")
    public void changeRoleApprove(@RequestBody @Valid List<ChangeUserRoleApproveRequest> requests) {
        userManagementService.changeRoleApprove(requests);
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("hasAnyRole('SUPER')")
    public void deleteUser(@PathVariable String id) {
        userManagementService.deleteUser(id);
    }

}
