
import json

import responses


def mock_out_post_users(id, email, status=201, **kwargs):
    url = 'https://auth.kagiso.io/api/v1/users/.json'
    data = {
        'id': id,
        'email': email,
        'first_name': kwargs.get('first_name', ''),
        'last_name': kwargs.get('last_name', ''),
        'is_staff': kwargs.get('is_staff', False),
        'is_superuser': kwargs.get('is_superuser', False),
        'confirmation_token': '49:1YkTO2:1VuxvGJre66xqQj6rkEXewmVs08',
        'email_confirmed': None,
        'profile': kwargs.get('profile'),
        'created': '2015-04-21T08:18:30.368602Z',
        'modified': '2015-04-21T08:18:30.374410Z'
    }

    responses.add(
        responses.POST,
        url,
        body=json.dumps(data),
        status=status
    )

    return url, data


def mock_out_put_users(id, email, status=200, **kwargs):
    url = 'https://auth.kagiso.io/api/v1/users/{id}/.json'.format(id=id)
    data = {
        'id': 1,
        'email': email,
        'first_name': kwargs.get('first_name', ''),
        'last_name': kwargs.get('last_name', ''),
        'is_staff': kwargs.get('is_staff', False),
        'is_superuser': kwargs.get('is_superuser', False),
        'profile': kwargs.get('profile'),
        'created': '2015-04-21T08:18:30.368602Z',
        'modified': '2015-04-21T08:18:30.374410Z'
    }

    responses.add(
        responses.PUT,
        url,
        body=json.dumps(data),
        status=status
    )

    return url, data


def mock_out_delete_users(id, status=204):
    url = 'https://auth.kagiso.io/api/v1/users/{id}/.json'.format(id=id)

    responses.add(
        responses.DELETE,
        url,
        status=status
    )

    return url


def mock_out_post_confirm_email(status=200):
    url = 'https://auth.kagiso.io/api/v1/confirm_email/.json'  # noqa

    responses.add(
        responses.POST,
        url,
        status=status
    )

    return url


def mock_out_get_reset_password(email, status=200):
    url = 'https://auth.kagiso.io/api/v1/reset_password/{email}/.json'.format(email=email)  # noqa
    data = {
        'reset_password_token': 'random_token',
    }

    responses.add(
        responses.GET,
        url,
        body=json.dumps(data),
        status=status,
    )

    return url, data


def mock_out_post_reset_password(email, status=200):
    url = 'https://auth.kagiso.io/api/v1/reset_password/{email}/.json'.format(email=email)  # noqa

    responses.add(
        responses.POST,
        url,
        status=status
    )

    return url


def mock_out_post_sessions(status=200, **kwargs):
    url = 'https://auth.kagiso.io/api/v1/sessions/.json'
    data = {
        'id': kwargs.get('id', 1),
        'email': kwargs.get('email'),
        'first_name': kwargs.get('first_name', ''),
        'last_name': kwargs.get('last_name', ''),
        'is_staff': kwargs.get('is_staff', False),
        'is_superuser': kwargs.get('is_superuser', False),
        'email_confirmed': None,
        'profile': kwargs.get('profile'),
        'created': '2015-04-21T08:18:30.368602Z',
        'modified': '2015-04-21T08:18:30.374410Z'
    }

    responses.add(
        responses.POST,
        url,
        body=json.dumps(data),
        status=status
    )

    return url, data


def mock_out_delete_sessions(id, status=200):
    url = 'https://auth.kagiso.io/api/v1/sessions/{id}/.json'.format(id=id)

    responses.add(
        responses.DELETE,
        url,
        status=status
    )

    return url
