import time
import datetime
import logging
from website import consts, settings

def get_license_status(license):
    status = consts.system_status_not_active
    # if not license:
    #     pass
    if license:
        now = datetime.datetime.now()
        timestamp_now = int(now.timestamp())

        expireat = int(license["expireat"])
        expireat_datetime = datetime.datetime.fromtimestamp(expireat)
        expireat_next30days = expireat_datetime + datetime.timedelta(days=30)
        expireat_next30days_timestamp = int(expireat_next30days.timestamp())

        time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())

        # logging.info(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(expireat)))
        # logging.info(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(expireat_next30days_timestamp)))
        # logging.info(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp_now)))

        if timestamp_now >= expireat_next30days_timestamp:
            status = consts.system_status_expire_atall
        elif timestamp_now >= expireat and timestamp_now < expireat_next30days_timestamp:
            status = consts.system_status_expire_but_ok
        elif timestamp_now < expireat:
            status = consts.system_status_activated

    return status