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

from flask import render_template, make_response, request
from flask_restx import Namespace, Resource

from .data_access_object import SchemaObject

dao = SchemaObject()

############################
# REST API
############################

api = Namespace('subsystems', description='SHARK subsystems')

@api.route("/")
class ListOfSubsystems(Resource):
    def get(self):
        return dao.schemas

    
@api.route("/<string:subsystem>")
class SubsystemList(Resource):
    def get(self, subsystem):
        opts = dao.read(subsystem)
        opts_dict = {o["name"]:o for o in opts }
        # hack!
        if "DROT_PosAng" in opts_dict:
            derotator = opts_dict["DROT_PosAng"]
            opts_dict["derotator"] = derotator
        return opts_dict

    
@api.route("/<string:subsystem>/<string:option>")
class Subsystem(Resource):
    def get(self, subsystem, option):
        opt = dao.read(subsystem)[option]
        return opt

