# -*- coding: utf-8 -*-

from django.conf import settings
from django_logit import logit
from json_render import json_render

from sales.models import SalesResponsibilityInfo


@logit
def supersr_oauthqr(request):
    brand_id = request.GET.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)

    return json_render(request, 'page/supersr_oauth_qrcode.html', unjsondumpsdict={
        'qr': settings.KODO_SUPERSR_AUTH_URL.format(brand_id)
    })


@logit
def supersr_oauth(request):
    brand_id = request.GET.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
    unionid = request.GET.get('unionid', '')

    SalesResponsibilityInfo.objects.update_or_create(brand_id=brand_id, unionid=unionid, defaults={
        'user_status': SalesResponsibilityInfo.ACTIVATED,
        'is_auth': True,
        'is_super': True,
    })

    return json_render(request, 'page/supersr_oauth_success.html', unjsondumpsdict={
    })
