# coding=utf-8
import datetime

from django.conf import settings
from django.db import transaction

from rpc.tool.error_code import gen, CODES
from api.models import CouponInfo
from api.models import Coupon
from api.models import COUPON_TYPE


def _is_ongoing(now):
    pass
    # 废弃但不删除
    # start = datetime.datetime.strptime(settings.BAIDU_COUPON_START_DATE, '%Y-%m-%d')
    # end = datetime.datetime.strptime(settings.BAIDU_COUPON_STOP_DATE, '%Y-%m-%d')
    # if now >= start and now <= end:
    #     return True
    # else:
    #     return False


def auto_append_user_couponinfo(user_id):
    raise gen(CODES.UNKNOWN_ERROR)
    # 废弃但不删除留着以后用
    #now = datetime.datetime.now()
    #if not _is_ongoing(now):
    #    return
    #with transaction.atomic():
    #    for coupon in Coupon.objects.filter(id__in=settings.BAIDU_COUPON_IDS):
    #        try:
    #            CouponInfo.objects.get(user_id=user_id, coupon=coupon)
    #            continue
    #        except:
    #            pass
    #        CouponInfo.objects.create(
    #            coupon=coupon,
    #            value=coupon.value,
    #            claimed_time=now,
    #            channel=settings.BAIDU_BUSINESS_CHANNEL,
    #            user_id=user_id,
    #            status=COUPON_TYPE.CLAIMED
    #        )
