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

import json

from django.conf import settings

from pai2.basemodels import PlatformMixin
from utils.redis.rkeys import APP_SETTINGS_INFO


r = settings.REDIS_CACHE


def set_app_settings_info(appset):
    """ 设置 APP 设置信息 """
    r.set(APP_SETTINGS_INFO % (appset.platform, appset.channel, appset.version), json.dumps(appset.data))


def del_app_settings_info(appset):
    """ 删除 APP 设置信息 """
    r.delete(APP_SETTINGS_INFO % (appset.platform, appset.channel, appset.version))


def get_app_settings_info(platform, channel, version):
    """ 获取 APP 设置信息 """
    platform = platform if isinstance(platform, int) else PlatformMixin.Platforms[platform]
    return json.loads(r.get(APP_SETTINGS_INFO % (platform, channel, version)) or '{}')
