package com.eactive.eai.manage.inflow;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/manage/inflow/group")
public class InflowGroupBucketController {

    @Autowired
    private InflowGroupBucketService bucketService;

    /**
     * 특정 그룹의 버킷 상태 조회
     * GET /manage/inflow/group/{groupId}/bucket-status
     */
    @GetMapping("/{groupId}/bucket-status")
    public ResponseEntity<?> getGroupBucketStatus(@PathVariable String groupId) {
        GroupBucketStatusDTO status = bucketService.getGroupBucketStatus(groupId);

        if (status == null) {
            Map<String, Object> error = new HashMap<>();
            error.put("success", false);
            error.put("message", "그룹을 찾을 수 없습니다: " + groupId);
            return ResponseEntity.ok(error);
        }

        Map<String, Object> result = new HashMap<>();
        result.put("success", true);
        result.put("data", status);
        return ResponseEntity.ok(result);
    }

    /**
     * 모든 그룹의 버킷 상태 조회
     * GET /manage/inflow/group/bucket-status
     */
    @GetMapping("/bucket-status")
    public ResponseEntity<?> getAllGroupBucketStatus() {
        List<GroupBucketStatusDTO> statusList = bucketService.getAllGroupBucketStatus();

        Map<String, Object> result = new HashMap<>();
        result.put("success", true);
        result.put("data", statusList);
        result.put("count", statusList.size());
        return ResponseEntity.ok(result);
    }
}
