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

# Third-party modules
from flask_restx import Namespace, Resource

# Custom modules
from .data_access_object import SchemaObject

sco = SchemaObject()

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

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

    
@api.route("/<string:subsystem>")
class SubsystemList(Resource):
    def get(self, subsystem):
        opts = sco.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 = sco.read(subsystem)[option]
        return opt

