#!/usr/bin/env python3

import sys
###
from signal import pause

try:
    from utils.configuration.app_configuration import AppConfiguration
except ImportError as e:
    print("Unable to import 'AppConfiguration' from 'utils.configuration.app_configuration.py' file at the 'main.py'")
    sys.exit(1)

try:
    from utils.database.app_database import AppDatabase
except ImportError as e:
    print("Unable to import 'AppDatabase' from 'utils.database.app_database.py' file at the 'main.py'")
    sys.exit(1)

try:
    from utils.boxes.app_boxes import AppBoxes
except ImportError as e:
    print("Unable to import 'AppDatabase' from 'utils.database.app_database.py' file at the 'main.py'")
    sys.exit(1)


#############
#############
#############


BTN_COUNTER = 0

def btn_pressed():
    global BTN_COUNTER
    print(f"button pressed | counter: {BTN_COUNTER}")
    BTN_COUNTER += 1

def btn_pressed_2():
    global BTN_COUNTER
    print(f"button pressed_2 | counter: {BTN_COUNTER}")
    BTN_COUNTER += 1

# main function
def main():
    print("\n-------> START \n")

    # Get the configuration, from file or parsed...
    configuration = AppConfiguration()

    ###
    ### DEBUG
    ###
    from pprint import pp
    # import pdb; pdb.set_trace()
    # pp(configuration.dict_values)

    # Set the used DB from the configuration...
    database = AppDatabase(configuration)

    ###
    ### LOCALSQLite
    ###
    # ### WORKS
    # foo = database.db.table_select_all(configuration.database_table_name_button_box)
    # import pdb; pdb.set_trace()
    # pp(foo)

    ###
    ### API
    ###
    # # import pdb; pdb.set_trace()
    # test_data = {
    #     # "id": "1"
    #     "id": "2"
    # }
    # foo = database.db.post(endpoint="api/box/use", json=test_data)
    # pp(foo)

    # bar = database.db.get(endpoint="api/box/use/count")
    # pp(bar)

    # Set the Button Boxes
    boxes = AppBoxes(configuration, database)

    import pdb; pdb.set_trace()
    pp(boxes)

    print("\n <------- FINISH \n")


if __name__=="__main__":
    main()