from Blueprints.BaseRequestParser import base_parser, handle_request
from Rest.ImagesREST import ImagesREST
from flask_restx import Namespace, Resource
from Rest.Answer import message_response_model

from Blueprints.APIModels import a_image, post_a_image_string

api = Namespace('Image', path='/images', description='Image related Operations')

a_image_response_single = message_response_model(a_image, single=True)
a_image_response_multiple = message_response_model(a_image)


@api.route('/<image_id>')
@api.doc(params={'image_id': 'Id of an image'})
class Image(Resource):
    @api.produces(["image/png"])
    @api.doc(parser=base_parser)
    def get(self, image_id):
        return handle_request(path_args=[image_id],
                              rest_function=ImagesREST.get_images)

    @api.doc(parser=base_parser)
    def delete(self, image_id):
        return handle_request(path_args=[image_id],
                              rest_function=ImagesREST.delete_images)


@api.route('/')
class Images(Resource):
    @api.doc(parser=base_parser)
    def get(self):
        return handle_request(rest_function=ImagesREST.get_my_images,
                              model=a_image_response_multiple)

    @api.doc(parser=base_parser, body=post_a_image_string)
    def put(self):
        return handle_request(json_data=True,
                              rest_function=ImagesREST.put_images,
                              model=a_image_response_single)
