package com.erp.controller;

import com.erp.service.ScreenFileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/screens")
@RequiredArgsConstructor
@Slf4j
public class ScreenFileController {

    private final ScreenFileService screenFileService;

    /**
     * GET /api/screens/{screenId}/components/files
     * 화면의 모든 컴포넌트 파일 조회 (컴포넌트별 그룹화)
     * 응답: { success, componentFiles, totalFiles, componentCount }
     */
    @GetMapping("/{screenId}/components/files")
    public ResponseEntity<Map<String, Object>> getScreenComponentFiles(
            @PathVariable String screenId) {
        Map<String, Object> result = screenFileService.getScreenComponentFiles(screenId);
        return ResponseEntity.ok(result);
    }

    /**
     * GET /api/screens/{screenId}/components/{componentId}/files
     * 특정 컴포넌트의 파일 목록 조회
     * 응답: { success, files, componentId, screenId }
     */
    @GetMapping("/{screenId}/components/{componentId}/files")
    public ResponseEntity<Map<String, Object>> getComponentFiles(
            @PathVariable String screenId,
            @PathVariable String componentId) {
        Map<String, Object> result = screenFileService.getComponentFiles(screenId, componentId);
        return ResponseEntity.ok(result);
    }
}
