#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2016 Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

import sys
import time

from flask import Flask
from flask import jsonify

timeout = int(sys.argv[1])

app = Flask(__name__)


@app.route("/1.1/infos")
def infos():
    time.sleep(timeout)
    return jsonify({
        "uuid": "6fa459ea-ee8a-3ca4-894e-db77e1europe"
    })


@app.route("/1.1/users")
def users():
    time.sleep(timeout)
    return jsonify({
        "total": 2,
        "items": [
            {
                "id": 42,
                "line_id": 3,
                "agent_id": 2,
                "firstname": "Bob",
                "lastname": "Dylan",
                "exten": "1632",
                "email": "bob@dylan.com",
                "mobile_phone_number": "0634321243"
            },
            {
                "id": 100,
                "line_id": 42,
                "agent_id": None,
                "firstname": "Charles",
                "lastname": "European",
                "exten": "9012",
                "email": "",
                "mobile_phone_number": ""
            }
        ]
    })


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8000, debug=True)
