from flask_restx import Namespace, Resource
from Blueprints.BaseRequestParser import base_parser, handle_request
from Rest.Answer import message_response_model
from Rest.DevicesREST import DevicesREST

from Blueprints.APIModels import a_device

api = Namespace('Device', path='/device/', description='Device related Operations')

device_activity_parser = base_parser.copy()
device_activity_parser.add_argument('device_id', location='args', required=True)
device_activity_parser.add_argument('device_name', location='args', required=False)

device_parser = base_parser.copy()
device_parser.add_argument('device_id', location='args', required=False)

a_device_response = message_response_model(a_device)


@api.route('/active')
class DeviceActivity(Resource):
    @api.doc(parser=device_activity_parser)
    def post(self):
        return handle_request(parser=device_activity_parser,
                              arg_dict={'device_id': None, 'device_name': ""},
                              rest_function=DevicesREST.set_device_active)


@api.route('/')
class Devices(Resource):
    @api.doc(parser=device_parser)
    def get(self):
        return handle_request(parser=device_parser,
                              arg_dict={'device_id': None},
                              model=a_device_response)
