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

obj_log = logging.getLogger("logger")


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

    @allure.step("创建Banner")
    def kw_joyhub_banner_create_post(self, position, platform, lang, rank_num, banner_type, status, interval_time, id=0, title="", sub_title="", image=None, link="", cover_image=None):
        """
        创建Banner管理业务关键字
        :param id: 主键，新增为0
        :param position: 位置
        :param title: 标题
        :param sub_title: 副标题
        :param image: 图片，格式{'url': 'https://xxx', 'name': 'xxx', 'mime_type': 'image/webp'}
        :param link: 链接
        :param platform: 适用平台(1PC 2手机)
        :param lang: 语言(en 英语 de 德语 ja 日语)
        :param rank_num: 排序号
        :param banner_type: 类型
        :param status: 状态 1-启用，2-停用
        :param interval_time: 轮播时间(秒)
        :param cover_image: 缩略图
        :return: 响应结果
        """
        obj_log.info(f"创建Banner - position: {position}, platform: {platform}, lang: {lang}, rankNum: {rank_num}, type: {banner_type}, status: {status}")

        if image is None:
            image = {'url': 'https://www.toendi.com/static/image/cd94c191561c4a37a04c78fca2913851.webp', 'name': 'Test Banner Image', 'mime_type': 'image/webp'}

        params = {
            "id": id,
            "position": position,
            "title": title,
            "subTitle": sub_title,
            "image": image,
            "link": link,
            "platform": platform,
            "lang": lang,
            "rankNum": rank_num,
            "type": banner_type,
            "status": status,
            "intervalTime": interval_time,
            "coverImage": cover_image
        }

        resp = self.kw_in_joyhub_banner_create_post(**params)
        obj_log.info(f"创建Banner响应: {resp}")

        return resp

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

        resp = self.kw_in_joyhub_banner_delete_delete(banner_id=banner_id)
        obj_log.info(f"删除Banner响应: {resp}")

        return resp

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

        resp = self.kw_in_joyhub_banner_delete_list_delete(ids=banner_ids)
        obj_log.info(f"批量删除Banner响应: {resp}")

        return resp

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

        resp = self.kw_in_joyhub_banner_get_get(banner_id=banner_id)
        obj_log.info(f"获得Banner详情响应: {resp}")

        return resp

    @allure.step("获得Banner分页列表")
    def kw_joyhub_banner_page_get(self, page_no=1, page_size=10, **kwargs):
        """
        获得Banner管理分页业务关键字
        :param page_no: 页码
        :param page_size: 每页条数
        :param position: 位置
        :param title: 标题
        :param sub_title: 副标题
        :param platform: 适用平台(1PC 2手机)
        :param lang: 语言
        :param banner_type: 类型
        :param status: 状态
        :return: 响应结果
        """
        obj_log.info(f"获得Banner分页列表 - pageNo: {page_no}, pageSize: {page_size}")

        params = {
            "pageNo": page_no,
            "pageSize": page_size,
            "position": kwargs.get("position", ""),
            "title": kwargs.get("title", ""),
            "subTitle": kwargs.get("sub_title", ""),
            "platform": kwargs.get("platform", ""),
            "lang": kwargs.get("lang", ""),
            "type": kwargs.get("banner_type", ""),
            "status": kwargs.get("status", "")
        }

        resp = self.kw_in_joyhub_banner_page_get(**params)
        obj_log.info(f"获得Banner分页列表响应: {resp}")

        return resp

    @allure.step("更新Banner")
    def kw_joyhub_banner_update_put(self, banner_id, position, platform, lang, rank_num, banner_type, status, interval_time, title="", sub_title="", image=None, link="", cover_image=None):
        """
        更新Banner管理业务关键字
        :param banner_id: 主键
        :param position: 位置
        :param title: 标题
        :param sub_title: 副标题
        :param image: 图片
        :param link: 链接
        :param platform: 适用平台(1PC 2手机)
        :param lang: 语言(en 英语 de 德语 ja 日语)
        :param rank_num: 排序号
        :param banner_type: 类型
        :param status: 状态 1-启用，2-停用
        :param interval_time: 轮播时间(秒)
        :param cover_image: 缩略图
        :return: 响应结果
        """
        obj_log.info(f"更新Banner - id: {banner_id}, position: {position}, platform: {platform}, lang: {lang}, rankNum: {rank_num}, type: {banner_type}, status: {status}")

        if image is None:
            image = {'url': 'https://www.toendi.com/static/image/cd94c191561c4a37a04c78fca2913851.webp', 'name': 'Updated Banner Image', 'mime_type': 'image/webp'}

        params = {
            "id": banner_id,
            "position": position,
            "title": title,
            "subTitle": sub_title,
            "image": image,
            "link": link,
            "platform": platform,
            "lang": lang,
            "rankNum": rank_num,
            "type": banner_type,
            "status": status,
            "intervalTime": interval_time,
            "coverImage": cover_image
        }

        resp = self.kw_in_joyhub_banner_update_put(**params)
        obj_log.info(f"更新Banner响应: {resp}")

        return resp