from flask import Flask
from flask_ask import Ask, statement,question
# from waitress import serve

app =  Flask(__name__)
ask =  Ask(app, "/")


@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

@ask.launch
def welcome():
    return question("Welcome to the Smart home")

@ask.intent('SwitchConnectIntent')
def SwitchHandle(WHICH_ACTION,WHICH_SWITCH,WHICH_DEVICE):
    print(WHICH_ACTION,WHICH_SWITCH,WHICH_DEVICE)
    Phrase = "PLEASE TURN {} {} FROM {}".format(WHICH_ACTION,WHICH_SWITCH,WHICH_DEVICE)
    return question(Phrase) 

@ask.intent('AMAZON.HelpIntent')
def help():
    Phrase = 'You can say turn on the switches to me, or you can say exit! How can I help?'
    reprompt = 'What can i help you with?'
    return question(Phrase) \
        .reprompt(reprompt)  

@ask.intent('AMAZON.CancelIntent') 
def canel():
    Phrase = 'Goodbye!'
    return question(Phrase)  

@ask.intent('AMAZON.FallbackIntent') 
def fallback():
    Phrase = "Hmm, I'm not sure. You can say turn on the switches to me or Help. What would you like to do?"
    reprompt = "I didn't catch that. What can I help you with?"
    return question(Phrase)  \
        .reprompt(reprompt)  

@ask.intent('AMAZON.StopIntent')
def stop():
    Phrase = 'enjoy the day! good bye'
    return question(Phrase)         

          
@ask.session_ended
def session_ended():
    return "{}", 200


# if __name__ == "__main__":
#      app.run()
#     serve(app, host='0.0.0.0', port=50100, threads=2)
#     app.run(debug=True, host="0.0.0.0", port=8080)