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

# Third-party modules
from flask_restx import Namespace, Resource

# Custom modules
from util.instances import RTC

api = Namespace('teccam', description='Real Time Control')


@api.route("/centroid")
class Centroid(Resource):

    def get(self):
        return RTC.centroid

    def put(self):
        cx_cy = api.payload
        RTC.centroid = list(map(float, cx_cy))

@api.route("/dark")
class Dark(Resource):

    def get(self):
        return RTC.todos_dark

    def put(self):
        name = api.payload
        return RTC.load_dark(name)

    def post(self):
        return RTC.new_dark()

    # def delete(self):
    #     subtract = api.payload
    #     return RTC.subtract_dark()
    
@api.route("/exptime")
class Exptime(Resource):

    def put(self):
        temp = api.payload
        return RTC.tint(temp)

@api.route("/gain")
class Gain(Resource):

    def get(self):
        return RTC.todos_gain

    def put(self):
        name = api.payload
        return RTC.load_gain(name)

    def post(self):
        gain_type, centroid_size = api.payload
        return RTC.new_gain(gain_type, centroid_size)

@api.route("/patrol")
class Size(Resource):

    def post(self):
        return RTC.patrol(True)

    def delete(self):
        return RTC.patrol(False)

@api.route("/temperature")
class Temperature(Resource):

    def put(self):
        temp = api.payload
        return RTC.temperature(temp)
