#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Third-party modules
from flask import make_response, render_template
from flask_restx import Namespace, Resource, fields

#############################################
# WEB
#############################################

web = Namespace('other', description='Web snippets')

@web.route("/display")
class Display(Resource):

    def get(self):
        data = {}
        return make_response(render_template("display.html", data=data))


@web.route("/button")
class Button(Resource):

    def get(self):
        data = {}
        return make_response(render_template("other/button.html", data=data))

    
@web.route("/fits")
class Fits(Resource):

    def get(self):
        # System modules
        import io

        # Third-party modules
        from astropy.io import fits
        from flask import send_file
        with open("./data/fits/test.fits", mode='rb') as hdul:
            data = hdul.read()
            fitsdata = send_file(
                io.BytesIO(data),
                mimetype='image/fits',
                as_attachment=True,
                download_name='ciccio.fits')

        return make_response(fitsdata)
