import os
from os import listdir
from os.path import isfile, join

from flask import request, jsonify, abort, Response
from flask_restful import Resource

from app.resource.ResultWrapper import *
from app.resource.ResponseBuilder import *

# shows a list of all todos, and lets you POST to add new tasks
class Strategies(Resource):
    def post(self):
        #args = parser.parse_args()
        #todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1
        #todo_id = 'todo%i' % todo_id
        #TODOS[todo_id] = {'task': args['task']}
        #return TODOS[todo_id], 201
        return ""                
    
    def get(self):
        userId = request.headers.get('token')
        if userId is None:
            userId = 'guest'
            
        mypath = './configure/strategy/' + userId + '/'
        strategyNames = []
        
        if os.path.exists(mypath):
            onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
            for name in onlyfiles:
                strategyNames.append(name[:-5])
        
        strategyDict = {userId: strategyNames}
        
        resultWrapper = ResultWrapper(strategyDict)
        
        return ResponseBuilder.build(resultWrapper)
