package at.procon.dip.domain.document.web;

import at.procon.dip.domain.document.dto.GenericDocumentDetailResponse;
import at.procon.dip.domain.document.service.GenericDocumentReadService;
import at.procon.dip.runtime.condition.ConditionalOnRuntimeMode;
import at.procon.dip.runtime.config.RuntimeMode;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
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("/v1/dip/documents")
@RequiredArgsConstructor
@ConditionalOnRuntimeMode(RuntimeMode.NEW)
public class GenericDocumentController {

    private final GenericDocumentReadService documentReadService;

    @GetMapping("/{id}")
    public ResponseEntity<GenericDocumentDetailResponse> getDocument(@PathVariable UUID id) {
        return documentReadService.findById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }
}
