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

from kodo.basemodels import PlatformMixin
from utils.redis.connect import r
from utils.redis.rkeys import APP_PATCH_INFO


def set_app_patch_info(apppatch):
    """ 设置 APP 补丁信息 """
    r.setjson(APP_PATCH_INFO % (apppatch.platform, apppatch.version, apppatch.src), apppatch.data)


def del_app_patch_info(apppatch):
    """ 删除 APP 补丁信息 """
    r.delete(APP_PATCH_INFO % (apppatch.platform, apppatch.version, apppatch.src))


def get_app_patch_info(platform, version, src):
    """ 获取 APP 补丁信息 """
    platform = platform if isinstance(platform, int) else PlatformMixin.Platforms.get(platform)
    return r.getjson(APP_PATCH_INFO % (platform, version, src))
