# -*- coding:utf-8 -*-
import os
import sys

current_file_path = os.path.abspath(__file__)
project_root = os.path.abspath(os.path.join(os.path.dirname(current_file_path), '../../../'))
if project_root not in sys.path:
    sys.path.insert(0, project_root)

from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
import allure

obj_log = log.get_logger()


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

    @allure.step("创建协议")
    def kw_joyhub_agreement_create_post(self, type, title, content, terminal="web", lang="en", rank_num=1, status=1, id=0):
        """
        创建协议业务关键字
        :param id: 主键，新增为0
        :param type: 类型（1隐私协议 2用户协议）
        :param title: 标题
        :param content: 内容
        :param terminal: 终端(1web 2app)
        :param lang: 语言 (en 英语 de 德语 ja 日语)
        :param rank_num: 排序号
        :param status: 状态 (1正常 2停用)
        :return: 响应结果
        """
        obj_log.info(f"创建协议 - type: {type}, title: {title}, content: {content[:50]}..., terminal: {terminal}, lang: {lang}, rank_num: {rank_num}, status: {status}")

        params = {
            "id": id,
            "type": type,
            "title": title,
            "content": content,
            "terminal": terminal,
            "lang": lang,
            "rankNum": rank_num,
            "status": status
        }

        resp = self.kw_in_joyhub_agreement_create_post(**params)
        obj_log.info(f"创建协议响应: {resp}")

        return resp

    @allure.step("删除协议")
    def kw_joyhub_agreement_delete_delete(self, agreement_id):
        """
        删除协议业务关键字
        :param agreement_id: 协议ID
        :return: 响应结果
        """
        obj_log.info(f"删除协议 - agreement_id: {agreement_id}")

        resp = self.kw_in_joyhub_agreement_delete_delete(agreement_id)
        obj_log.info(f"删除协议响应: {resp}")

        return resp

    @allure.step("批量删除协议")
    def kw_joyhub_agreement_delete_list_delete(self, agreement_ids):
        """
        批量删除协议业务关键字
        :param agreement_ids: 协议ID列表
        :return: 响应结果
        """
        obj_log.info(f"批量删除协议 - agreement_ids: {agreement_ids}")

        resp = self.kw_in_joyhub_agreement_delete_list_delete(agreement_ids)
        obj_log.info(f"批量删除协议响应: {resp}")

        return resp

    @allure.step("导出协议Excel")
    def kw_joyhub_agreement_export_excel_get(self, **kwargs):
        """
        导出协议Excel业务关键字
        :param kwargs: 查询参数（type, title, content, status）
        :return: 响应结果
        """
        obj_log.info(f"导出协议Excel - 参数: {kwargs}")

        resp = self.kw_in_joyhub_agreement_export_excel_get(**kwargs)
        obj_log.info(f"导出协议Excel响应: {resp}")

        return resp

    @allure.step("获得协议详情")
    def kw_joyhub_agreement_get_get(self, agreement_id):
        """
        获得协议详情业务关键字
        :param agreement_id: 协议ID
        :return: 响应结果
        """
        obj_log.info(f"获得协议详情 - agreement_id: {agreement_id}")

        resp = self.kw_in_joyhub_agreement_get_get(agreement_id)
        obj_log.info(f"获得协议详情响应: {resp}")

        return resp

    @allure.step("获得协议分页列表")
    def kw_joyhub_agreement_page_get(self, **kwargs):
        """
        获得协议分页列表业务关键字
        :param kwargs: 查询参数（type, title, content, status, page_no, page_size）
        :return: 响应结果
        """
        obj_log.info(f"获得协议分页列表 - 参数: {kwargs}")

        resp = self.kw_in_joyhub_agreement_page_get(**kwargs)
        obj_log.info(f"获得协议分页列表响应: {resp}")

        return resp

    @allure.step("更新协议")
    def kw_joyhub_agreement_update_put(self, agreement_id, type, title, content, terminal="web", lang="en", rank_num=1, status=1):
        """
        更新协议业务关键字
        :param agreement_id: 协议ID
        :param type: 类型（1隐私协议 2用户协议）
        :param title: 标题
        :param content: 内容
        :param terminal: 终端(1web 2app)
        :param lang: 语言 (en 英语 de 德语 ja 日语)
        :param rank_num: 排序号
        :param status: 状态 (1正常 2停用)
        :return: 响应结果
        """
        obj_log.info(f"更新协议 - agreement_id: {agreement_id}, type: {type}, title: {title}, content: {content[:50]}..., terminal: {terminal}, lang: {lang}, rank_num: {rank_num}, status: {status}")

        params = {
            "id": agreement_id,
            "type": type,
            "title": title,
            "content": content,
            "terminal": terminal,
            "lang": lang,
            "rankNum": rank_num,
            "status": status
        }

        resp = self.kw_in_joyhub_agreement_update_put(**params)
        obj_log.info(f"更新协议响应: {resp}")

        return resp
