package at.procon.eventhub.tachograph.api;

import at.procon.eventhub.tachograph.service.UnsupportedTachographExtractionException;
import java.time.OffsetDateTime;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice(basePackageClasses = TachographIngestionController.class)
public class TachographApiExceptionHandler {

    @ExceptionHandler(UnsupportedTachographExtractionException.class)
    public ResponseEntity<Map<String, Object>> handleUnsupportedExtraction(UnsupportedTachographExtractionException ex) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Map.of(
                "error", "UNSUPPORTED_TACHOGRAPH_EXTRACTION",
                "message", ex.getMessage(),
                "timestamp", OffsetDateTime.now().toString()
        ));
    }
}
