import logging
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface

obj_log = logging.getLogger("logger")


class AppVersionManage(DlzhanInterface):
    def __init__(self):
        super().__init__()

    @allure.step("创建app版本号")
    def kw_joyhub_appversion_create_post(self, store_name, version, download_url, is_on, status, id=0):
        """
        创建app版本号管理业务关键字
        :param id: 主键，新增为0
        :param store_name: 应用商店
        :param version: 版本号
        :param download_url: 商城下载地址
        :param is_on: 是否上架（1是，2否）
        :param status: 状态 (1正常 2停用)
        :return: 响应结果
        """
        obj_log.info(f"创建app版本号 - storeName: {store_name}, version: {version}, downloadUrl: {download_url}, isOn: {is_on}, status: {status}")

        params = {
            "id": id,
            "storeName": store_name,
            "version": version,
            "downloadUrl": download_url,
            "isOn": is_on,
            "status": status
        }

        resp = self.kw_in_joyhub_appversion_create_post(**params)
        obj_log.info(f"创建app版本号响应: {resp}")

        return resp

    @allure.step("删除app版本号")
    def kw_joyhub_appversion_delete_delete(self, appversion_id):
        """
        删除app版本号管理业务关键字
        :param appversion_id: app版本号编号
        :return: 响应结果
        """
        obj_log.info(f"删除app版本号 - id: {appversion_id}")

        resp = self.kw_in_joyhub_appversion_delete_delete(appversion_id=appversion_id)
        obj_log.info(f"删除app版本号响应: {resp}")

        return resp

    @allure.step("批量删除app版本号")
    def kw_joyhub_appversion_delete_list_delete(self, appversion_ids):
        """
        批量删除app版本号管理业务关键字
        :param appversion_ids: app版本号编号列表
        :return: 响应结果
        """
        obj_log.info(f"批量删除app版本号 - ids: {appversion_ids}")

        resp = self.kw_in_joyhub_appversion_delete_list_delete(ids=appversion_ids)
        obj_log.info(f"批量删除app版本号响应: {resp}")

        return resp

    @allure.step("导出app版本号Excel")
    def kw_joyhub_appversion_export_excel_get(self, page_no=1, page_size=10, **kwargs):
        """
        导出app版本号管理 Excel业务关键字
        :param page_no: 页码
        :param page_size: 每页条数
        :param store_name: 应用商店
        :param version: 版本号
        :param download_url: 商城下载地址
        :param is_on: 是否上架
        :param status: 状态
        :return: 响应结果
        """
        obj_log.info(f"导出app版本号Excel - pageNo: {page_no}, pageSize: {page_size}")

        params = {
            "pageNo": page_no,
            "pageSize": page_size,
            "storeName": kwargs.get("store_name", ""),
            "version": kwargs.get("version", ""),
            "downloadUrl": kwargs.get("download_url", ""),
            "isOn": kwargs.get("is_on", ""),
            "status": kwargs.get("status", "")
        }

        resp = self.kw_in_joyhub_appversion_export_excel_get(**params)
        obj_log.info(f"导出app版本号Excel响应: {resp}")

        return resp

    @allure.step("获得app版本号详情")
    def kw_joyhub_appversion_get_get(self, appversion_id):
        """
        获得app版本号管理业务关键字
        :param appversion_id: app版本号编号
        :return: 响应结果
        """
        obj_log.info(f"获得app版本号详情 - id: {appversion_id}")

        resp = self.kw_in_joyhub_appversion_get_get(appversion_id=appversion_id)
        obj_log.info(f"获得app版本号详情响应: {resp}")

        return resp

    @allure.step("获得导入app版本号模板")
    def kw_joyhub_appversion_get_import_template_get(self):
        """
        获得导入app版本号管理模板业务关键字
        :return: 响应结果
        """
        obj_log.info("获得导入app版本号模板")

        resp = self.kw_in_joyhub_appversion_get_import_template_get()
        obj_log.info(f"获得导入app版本号模板响应: {resp}")

        return resp

    @allure.step("导入app版本号Excel")
    def kw_joyhub_appversion_import_excel_post(self, update_support, user_id=None):
        """
        导入app版本号管理Excel业务关键字
        :param update_support: 是否支持更新
        :param user_id: 创建人-为空则取当前人
        :return: 响应结果
        """
        obj_log.info(f"导入app版本号Excel - updateSupport: {update_support}, userId: {user_id}")

        params = {
            "updateSupport": update_support
        }
        if user_id is not None:
            params["userId"] = user_id

        resp = self.kw_in_joyhub_appversion_import_excel_post(**params)
        obj_log.info(f"导入app版本号Excel响应: {resp}")

        return resp

    @allure.step("获得app版本号分页列表")
    def kw_joyhub_appversion_page_get(self, page_no=1, page_size=10, **kwargs):
        """
        获得app版本号管理分页业务关键字
        :param page_no: 页码
        :param page_size: 每页条数
        :param store_name: 应用商店
        :param version: 版本号
        :param download_url: 商城下载地址
        :param is_on: 是否上架
        :param status: 状态
        :return: 响应结果
        """
        obj_log.info(f"获得app版本号分页列表 - pageNo: {page_no}, pageSize: {page_size}")

        params = {
            "pageNo": page_no,
            "pageSize": page_size,
            "storeName": kwargs.get("store_name", ""),
            "version": kwargs.get("version", ""),
            "downloadUrl": kwargs.get("download_url", ""),
            "isOn": kwargs.get("is_on", ""),
            "status": kwargs.get("status", "")
        }

        resp = self.kw_in_joyhub_appversion_page_get(**params)
        obj_log.info(f"获得app版本号分页列表响应: {resp}")

        return resp

    @allure.step("更新app版本号")
    def kw_joyhub_appversion_update_put(self, appversion_id, store_name, version, download_url, is_on, status):
        """
        更新app版本号管理业务关键字
        :param appversion_id: 主键
        :param store_name: 应用商店
        :param version: 版本号
        :param download_url: 商城下载地址
        :param is_on: 是否上架（1是，2否）
        :param status: 状态 (1正常 2停用)
        :return: 响应结果
        """
        obj_log.info(f"更新app版本号 - id: {appversion_id}, storeName: {store_name}, version: {version}, downloadUrl: {download_url}, isOn: {is_on}, status: {status}")

        params = {
            "id": appversion_id,
            "storeName": store_name,
            "version": version,
            "downloadUrl": download_url,
            "isOn": is_on,
            "status": status
        }

        resp = self.kw_in_joyhub_appversion_update_put(**params)
        obj_log.info(f"更新app版本号响应: {resp}")

        return resp
