import os

import requests

GENERATED_TOKEN_KEY = "model_container_pregenerated_token"
LOGIN_TOKEN_KEY = "login-token"


def delete(**kwargs):
    if os.environ.get(GENERATED_TOKEN_KEY):
        cookies = headers = {LOGIN_TOKEN_KEY: os.environ.get(GENERATED_TOKEN_KEY)}
        kwargs.update(dict(cookies=cookies, headers=headers))
    return requests.delete(**kwargs)


def get(**kwargs):
    if os.environ.get(GENERATED_TOKEN_KEY):
        cookies = headers = {LOGIN_TOKEN_KEY: os.environ.get(GENERATED_TOKEN_KEY)}
        kwargs.update(dict(cookies=cookies, headers=headers))
    return requests.get(**kwargs)


def head(**kwargs):
    if os.environ.get(GENERATED_TOKEN_KEY):
        cookies = headers = {LOGIN_TOKEN_KEY: os.environ.get(GENERATED_TOKEN_KEY)}
        kwargs.update(dict(cookies=cookies, headers=headers))
    return requests.head(**kwargs)


def patch(**kwargs):
    if os.environ.get(GENERATED_TOKEN_KEY):
        cookies = headers = {LOGIN_TOKEN_KEY: os.environ.get(GENERATED_TOKEN_KEY)}
        kwargs.update(dict(cookies=cookies, headers=headers))
    return requests.patch(**kwargs)


def post(**kwargs):
    if os.environ.get(GENERATED_TOKEN_KEY):
        cookies = headers = {LOGIN_TOKEN_KEY: os.environ.get(GENERATED_TOKEN_KEY)}
        kwargs.update(dict(cookies=cookies, headers=headers))
    return requests.post(**kwargs)


def put(**kwargs):
    if os.environ.get(GENERATED_TOKEN_KEY):
        cookies = headers = {LOGIN_TOKEN_KEY: os.environ.get(GENERATED_TOKEN_KEY)}
        kwargs.update(dict(cookies=cookies, headers=headers))
    return requests.put(**kwargs)
