package dev.fyloz.trial.colorrecipesexplorer.exception.model

import dev.fyloz.trial.colorrecipesexplorer.exception.RestException
import dev.fyloz.trial.colorrecipesexplorer.model.Model
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus

class EntityNotFoundException(modelType: Class<out Model>, val identifierType: IdentifierType, val identifierName: String, val requestedId: Any) : ModelException(modelType) {
    constructor(modelType: Class<out Model>, identifierType: IdentifierType, requestedId: Any) : this(modelType, identifierType, identifierType.name, requestedId)
}

@ResponseStatus(HttpStatus.NOT_FOUND)
class EntityNotFoundRestException(val value: Any) : RestException(HttpStatus.NOT_FOUND) {
    override val exceptionMessage: String = "An entity could not be found with the given identifier"

    override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
        val id = value
    }
}
