'''
    Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

from werkzeug.exceptions import BadRequest, Unauthorized, NotFound, InternalServerError
from connexion.exceptions import ProblemException


class MapserviceBadRequest(ProblemException, BadRequest):
    def __init__(
        self,
        type="bad-request",
        title=None,
        detail=None,
        instance=None,
        **kwargs
    ):
        super(MapserviceBadRequest, self).__init__(
            status=400,
            title="Bad Request",
            detail=detail,
            type=type,
            instance=instance,
            **kwargs
        )


class MapserviceUnauthorized(ProblemException, Unauthorized):
    def __init__(
        self,
        type="unauthorized",
        title="Access denied",
        detail="You need to login to access the requested resource",
        instance=None,
        **kwargs
    ):
        super(MapserviceUnauthorized, self).__init__(
            status=401,
            title=title,
            detail=detail,
            type=type,
            instance=instance,
            **kwargs
        )


class MapserviceNotFound(ProblemException, NotFound):
    def __init__(
        self,
        type="not-found",
        title="Resouce not found",
        detail="The requested resource was not found",
        instance=None,
        **kwargs
    ):
        super(MapserviceNotFound, self).__init__(
            status=404,
            title=title,
            detail=detail,
            type=type,
            instance=instance,
            **kwargs
        )


class MapserviceInternalServerError(ProblemException, InternalServerError):
    def __init__(
        self,
        type="internal-server-error",
        title=None,
        detail=None,
        instance=None,
        **kwargs
    ):
        super(MapserviceInternalServerError, self).__init__(
            status=500,
            title="Internal Server Error",
            detail=detail,
            type=type,
            instance=instance,
            **kwargs
        )
