package gc.mda.signal_batch.domain.ship.controller;

import gc.mda.signal_batch.domain.ship.dto.ShipImageDto;
import gc.mda.signal_batch.domain.ship.service.ShipImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/v1/shipimg")
@RequiredArgsConstructor
@Tag(name = "Ship Image", description = "선박 이미지 API")
public class ShipImageController {

    private final ShipImageService shipImageService;

    @GetMapping("/{imo}")
    @Operation(
            summary = "선박 이미지 경로 조회",
            description = "IMO 번호로 선박 이미지 경로 목록을 조회합니다. 프론트엔드에서 썸네일은 path + '_1.jpg', 원본은 path + '_2.jpg'를 사용합니다."
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "조회 성공 (데이터 없으면 빈 배열 반환)",
                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = ShipImageDto.class)))
            )
    })
    public ResponseEntity<List<ShipImageDto>> getShipImages(
            @Parameter(description = "IMO 번호", example = "9141833")
            @PathVariable Integer imo) {

        log.debug("Requesting ship images for IMO: {}", imo);

        List<ShipImageDto> images = shipImageService.getImagesByImo(imo);

        log.debug("Found {} images for IMO: {}", images.size(), imo);

        return ResponseEntity.ok(images);
    }
}
