# Path: main.py

# 
# Path: models/love.py
# class Love(ndb.Model):
#     """Models an instance of sent love."""
#     message = ndb.TextProperty()
#     recipient_key = ndb.KeyProperty(kind=Employee)
#     secret = ndb.BooleanProperty(default=False)
#     sender_key = ndb.KeyProperty(kind=Employee)
#     timestamp = ndb.DateTimeProperty(auto_now_add=True)
#     company_values = ndb.StringProperty(repeated=True)
# 
#     @property
#     def seconds_since_epoch(self):
#         return int(mktime(self.timestamp.timetuple()))


from flask import request
from flask import Response
from google.appengine.api import taskqueue
from google.appengine.ext import ndb
from main import app
from models import Love
import logic.employee
import logic.notifier
import logic.love
import logic.love_count
import logic.love_link


# This task has a web UI to trigger it, so let's use POST
@app.route('/tasks/employees/load/csv', methods=['POST'])
def load_employees_from_csv():
    logic.employee.load_employees_from_csv()
    # we need to rebuild the love count index as the departments may have changed.
    taskqueue.add(url='/tasks/love_count/rebuild')
    return Response(status=200)


# One-off tasks are much easier to trigger using GET
@app.route('/tasks/employees/combine', methods=['GET'])
def combine_employees():
    old_username, new_username = request.args['old'], request.args['new']
    if not old_username:
        return Response(response='{} is not a valid username'.format(old_username), status=400)
    elif not new_username:
        return Response(response='{} is not a valid username'.format(new_username), status=400)

    logic.employee.combine_employees(old_username, new_username)
    return Response(status=200)


@app.route('/tasks/index/rebuild', methods=['GET'])
def rebuild_index():
    logic.employee.rebuild_index()
    return Response(status=200)



# Path: main.py

# 
# Path: models/love.py
# class Love(ndb.Model):
#     """Models an instance of sent love."""
#     message = ndb.TextProperty()
#     recipient_key = ndb.KeyProperty(kind=Employee)
#     secret = ndb.BooleanProperty(default=False)
#     sender_key = ndb.KeyProperty(kind=Employee)
#     timestamp = ndb.DateTimeProperty(auto_now_add=True)
#     company_values = ndb.StringProperty(repeated=True)
# 
#     @property
#     def seconds_since_epoch(self):
#         return int(mktime(self.timestamp.timetuple()))


# Path: views/tasks.py
from flask import request
from flask import Response
from google.appengine.api import taskqueue
from google.appengine.ext import ndb
from main import app
from models import Love
import logic.employee
import logic.notifier
import logic.love
import logic.love_count
import logic.love_link



# This task has a web UI to trigger it, so let's use POST
@app.route('/tasks/employees/load/csv', methods=['POST'])
def load_employees_from_csv():
    logic.employee.load_employees_from_csv()
    # we need to rebuild the love count index as the departments may have changed.
    taskqueue.add(url='/tasks/love_count/rebuild')
    return Response(status=200)


# One-off tasks are much easier to trigger using GET
@app.route('/tasks/employees/combine', methods=['GET'])
def combine_employees():
    old_username, new_username = request.args['old'], request.args['new']
    if not old_username:
        return Response(response='{} is not a valid username'.format(old_username), status=400)
    elif not new_username:
        return Response(response='{} is not a valid username'.format(new_username), status=400)

    logic.employee.combine_employees(old_username, new_username)
    return Response(status=200)


@app.route('/tasks/index/rebuild', methods=['GET'])
def rebuild_index():
    logic.employee.rebuild_index()
    return Response(status=200)



@app.route('/tasks/love/email', methods=['POST'])