# Path: app/state.py
# class State:
# class ProgramNotFound(Exception):
#     def __init__(self, is_hd=True):
#     def set_model(self, is_hd):
#     def start_program(self, name, params={}):
#     def stop_program(self):
#     def _get_program(self, name):
#     def _set_brightness(self, params):
#     def _set_rotation(self, params):
#     def _start_process(self, program, params):
#         def run_program(self):
# 
# Path: app/state.py
# class ProgramNotFound(Exception):
#     pass


from flask import request
from flask_restful import Resource, abort, reqparse
from app import state
from app.state import ProgramNotFound



class SetProgram(Resource):

    def put(self, program):
        parser = reqparse.RequestParser()
        parser.add_argument('brightness', type=float)
        parser.add_argument('rotation', type=int)
        args = parser.parse_args()

        try:
            state.start_program(program, args)
        except ProgramNotFound as e:
            abort(404, error="Program '{}' not found".format(e))
        except ValueError as e:
            abort(400, error=str(e))
        return {"success": "Program '{}' started".format(program)}


class StopProgram(Resource):

    def put(self):

# Path: app/state.py
# class State:
# class ProgramNotFound(Exception):
#     def __init__(self, is_hd=True):
#     def set_model(self, is_hd):
#     def start_program(self, name, params={}):
#     def stop_program(self):
#     def _get_program(self, name):
#     def _set_brightness(self, params):
#     def _set_rotation(self, params):
#     def _start_process(self, program, params):
#         def run_program(self):
# 
# Path: app/state.py
# class ProgramNotFound(Exception):
#     pass


# Path: app/api.py
from flask import request
from flask_restful import Resource, abort, reqparse
from app import state
from app.state import ProgramNotFound




class SetProgram(Resource):

    def put(self, program):
        parser = reqparse.RequestParser()
        parser.add_argument('brightness', type=float)
        parser.add_argument('rotation', type=int)
        args = parser.parse_args()

        try:
            state.start_program(program, args)
        except ProgramNotFound as e:
            abort(404, error="Program '{}' not found".format(e))
        except ValueError as e:
            abort(400, error=str(e))
        return {"success": "Program '{}' started".format(program)}


class StopProgram(Resource):

    def put(self):

        state.stop_program()