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

'''REST API for Switch related operations'''

# System modules

# Third-party modules
from flask import request

from .baseresource import ResourceDev


# @api.route("/dome/light")
# @api.route("/telescope/lamp")
# @api.route("/camera/power")
class State(ResourceDev):
    '''Manage a switch state.'''

    def __init__(self, *args, **kwargs):
        '''Constructor.'''

        super().__init__(self, *args, **kwargs)
        self.dev = kwargs["dev"]

    def get(self):
        '''Check if the switch on or off.'''
        res = {
            "response": self.dev.state,
            "error": self.dev.error,
            "timestamp": self.timestamp,
        }
        return res

    def put(self):
        '''Switch on or off.'''

        state = request.json
        self.dev.state = state
        res = {
            "response": self.dev.state,
            "error": self.dev.error,
            "timestamp": self.timestamp,
        }
        return res
