package space.nstart.pcp.tle_monitoring_service.configuration

import org.springframework.http.ResponseEntity
import org.springframework.validation.FieldError
import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.support.WebExchangeBindException
import reactor.core.publisher.Mono
import kotlin.collections.forEach
import kotlin.collections.set
import kotlin.to

class CustomValidationException(message: String) : RuntimeException(message)
class CustomErrorException(message: String) : RuntimeException(message)


@ControllerAdvice
class GlobalExceptionHandler {

    @ExceptionHandler(CustomValidationException::class)
    fun handleValidation(ex: CustomValidationException): ResponseEntity<Map<String, String>> {
        return ResponseEntity.badRequest()
            .body(mapOf("error" to ex.message!!))
    }
    @ExceptionHandler(CustomErrorException::class)
    fun handleError(ex: CustomErrorException): ResponseEntity<Map<String, String>> {
        return ResponseEntity.internalServerError()
            .body(mapOf("error" to ex.message!!))
    }
}