package com.caliverse.admin.domain.api;

import com.caliverse.admin.domain.request.GroupRequest;
import com.caliverse.admin.domain.response.GroupResponse;
import com.caliverse.admin.domain.service.GroupService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "권한 설정", description = "권한 설정 메뉴 api 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/groups")
public class GroupController {

    private final GroupService groupService;

    // 권한 설정 리스트 조회
    @GetMapping("/list")
    public ResponseEntity<GroupResponse> getGroupList(
            @RequestParam Map<String, String> requestParams){
        return ResponseEntity.ok().body(groupService.getGroupList(requestParams));
    }

    // 권한 설정 상세 조회
    @GetMapping("/detail/{group_id}")
    public ResponseEntity<GroupResponse> getDetail(
            @PathVariable("group_id") String groupId){
        return ResponseEntity.ok().body(groupService.getGroupDetail(groupId));
    }

    //권한 그룹 등록
    @PostMapping
    public ResponseEntity<GroupResponse> postAdminGroup(
            @RequestBody GroupRequest groupRequest) {
        return ResponseEntity.ok().body(groupService.postAdminGroup(groupRequest));
    }
    //그룹 권한 수정
    @PutMapping("/{group_id}")
    public ResponseEntity<GroupResponse> updateAdminGroup(
            @PathVariable("group_id") String groupId,@RequestBody GroupRequest groupRequest) {
        return ResponseEntity.ok().body(groupService.updateAdminGroup(groupId, groupRequest));
    }

    //그룹 삭제
    @DeleteMapping
    public ResponseEntity<GroupResponse> deleteAdminGroup(
            @RequestBody GroupRequest groupRequest) {
        return ResponseEntity.ok().body(groupService.deleteAdminGroup(groupRequest));
    }

}
