# coding: utf-8
# Copyright 2017 video++ Project, SJTU MediaLab
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from datetime import datetime
import shutil

from flask import request, session, jsonify, abort
from sqlalchemy import func

from vpp import log
from vpp import env
from vpp.config import CONF
from vpp.api.v1 import vpp_api as api
from vpp.db import models
from vpp.db.api import db_api, get_db_session
from vpp.api.v1 import auth
from vpp.job.context import JobState
from vpp.task.context import TaskState
from vpp import exceptions as excepts

LOG = log.get_logger(__name__, CONF.server_log_file)


@api.route("/users/<username>", methods=['GET'])
def user_GET(username):
    """API for get user specified by the username
    """
    user = auth.verify_user_or_abort(request.headers, username=username)

    resp = {
        "status": True,
        "message": "",
        "user": {
            "username": user.username,
            "email": user.email,
            "token": user.token,
            "user_url": "%s/api/users/%s" % (env.SERVER_URL, user.username),
        }
    }
    return jsonify(resp)


@api.route("/users", methods=['POST'])
def user_CREATE():
    """API for create a new user

    username, password, email should be provided in the request body
    """