import requests
from flask import Flask, json, request
import time
from datetime import datetime, timedelta
import random 

app = Flask(__name__)

datenow = datetime.utcnow()
dayssub = timedelta(days=random.randrange(3,10, 1))
hourssub = timedelta(hours=random.randrange(1,12, 1))
minutessub = timedelta(minutes=random.randrange(1,59, 1))
secondsssub = timedelta(seconds=random.randrange(1,59, 1))

datepaid = datenow - dayssub - hourssub - minutessub - secondsssub
lastchargeday = datepaid.strftime("%Y-%m-%dT%H:%M:%S+00:00")

fakeIdentity = {
    "data": {
        "attributes": {
            "email": "some_email@email.com",
        }
    },
    "included": [
        {
            "attributes": {
                "currently_entitled_amount_cents": 1500,
                "last_charge_date": lastchargeday,
                "last_charge_status": "Paid"
            },
            "id": "2",
            "type": "member"
        },
        {
            "attributes": {
                "title": "Supporter"
            },
            "id": "2",
            "type": "reward"
        },
        {
            "attributes": {
                "amount_cents": 1500,
                "last_charge_date": lastchargeday,
                "last_charge_status": "Paid"
            },
            "id": "3",
            "type": "pledge"
        }
    ],
    "links": {
        "self": "https://www.patreon.com/api/oauth2/v2/user/1"
    }
}


@app.route('/_oauth2/authorize', methods=['GET'])
def get_authorize():
    response_type = request.args.get('response_type')
    client_id = request.args.get('client_id')
    redirect_uri = request.args.get('redirect_uri')
    time.sleep(3)
    r = requests.get(redirect_uri+'?'+'code=whatever&state=')
    return json.dumps({})

@app.route('/_api/oauth2/token', methods=['POST'])
def post_token():
    print(request)
    return json.dumps({"access_token":"whatever2whatever2whatever2whatever2whatever2whatever2"})

@app.route('/_api/oauth2/api/current_user', methods=['GET'])
def get_current_user():
    return json.dumps({})

@app.route('/_api/oauth2/v2/identity', methods=['GET'])
def get_identity():
    print(request)
    return json.dumps(fakeIdentity)

if __name__ == '__main__':
    app.run(port=12345)