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

obj_log = logging.getLogger("logger")


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

    @allure.step("创建岗位")
    def kw_joyhub_post_create_post(self, name, code, sort, status, remark=""):
        """
        创建岗位业务关键字
        :param name: 岗位名称
        :param code: 岗位编码
        :param sort: 显示顺序
        :param status: 状态
        :param remark: 备注
        :return: 响应结果
        """
        obj_log.info(f"创建岗位 - name: {name}, code: {code}, sort: {sort}, status: {status}, remark: {remark}")
        
        params = {
            "name": name,
            "code": code,
            "sort": sort,
            "status": status
        }
        
        if remark:
            params["remark"] = remark
        
        resp = self.kw_in_joyhub_post_create_post(**params)
        obj_log.info(f"创建岗位响应: {resp}")
        
        return resp

    @allure.step("删除岗位")
    def kw_joyhub_post_delete_post(self, post_id):
        """
        删除岗位业务关键字
        :param post_id: 岗位编号
        :return: 响应结果
        """
        obj_log.info(f"删除岗位 - id: {post_id}")
        
        resp = self.kw_in_joyhub_post_delete_post(id=post_id)
        obj_log.info(f"删除岗位响应: {resp}")
        
        return resp

    @allure.step("批量删除岗位")
    def kw_joyhub_post_delete_list_post(self, ids):
        """
        批量删除岗位业务关键字
        :param ids: 岗位编号列表
        :return: 响应结果
        """
        obj_log.info(f"批量删除岗位 - ids: {ids}")
        
        resp = self.kw_in_joyhub_post_delete_list_post(ids=ids)
        obj_log.info(f"批量删除岗位响应: {resp}")
        
        return resp

    @allure.step("岗位管理导出")
    def kw_joyhub_post_export_get(self, pageNo=1, pageSize=10, code="", name="", status=None):
        """
        岗位管理导出业务关键字
        :param pageNo: 页码
        :param pageSize: 每页条数
        :param code: 岗位编码（模糊匹配）
        :param name: 岗位名称（模糊匹配）
        :param status: 状态
        :return: 响应结果
        """
        obj_log.info(f"岗位管理导出 - pageNo: {pageNo}, pageSize: {pageSize}, code: {code}, name: {name}, status: {status}")
        
        params = {
            "pageNo": pageNo,
            "pageSize": pageSize
        }
        
        if code:
            params["code"] = code
        if name:
            params["name"] = name
        if status is not None:
            params["status"] = status
        
        resp = self.kw_in_joyhub_post_export_get(**params)
        obj_log.info(f"岗位管理导出响应: {resp}")
        
        return resp

    @allure.step("获得岗位信息")
    def kw_joyhub_post_get_get(self, post_id):
        """
        获得岗位信息业务关键字
        :param post_id: 岗位编号
        :return: 响应结果
        """
        obj_log.info(f"获得岗位信息 - id: {post_id}")
        
        resp = self.kw_in_joyhub_post_get_get(id=post_id)
        obj_log.info(f"获得岗位信息响应: {resp}")
        
        return resp

    @allure.step("获取岗位全列表")
    def kw_joyhub_post_list_all_simple_get(self):
        """
        获取岗位全列表业务关键字
        :return: 响应结果
        """
        obj_log.info("获取岗位全列表")
        
        resp = self.kw_in_joyhub_post_list_all_simple_get()
        obj_log.info(f"获取岗位全列表响应: {resp}")
        
        return resp

    @allure.step("获得岗位分页列表")
    def kw_joyhub_post_page_get(self, pageNo=1, pageSize=10, code="", name="", status=None):
        """
        获得岗位分页列表业务关键字
        :param pageNo: 页码
        :param pageSize: 每页条数
        :param code: 岗位编码（模糊匹配）
        :param name: 岗位名称（模糊匹配）
        :param status: 状态
        :return: 响应结果
        """
        obj_log.info(f"获得岗位分页列表 - pageNo: {pageNo}, pageSize: {pageSize}, code: {code}, name: {name}, status: {status}")
        
        params = {
            "pageNo": pageNo,
            "pageSize": pageSize
        }
        
        if code:
            params["code"] = code
        if name:
            params["name"] = name
        if status is not None:
            params["status"] = status
        
        resp = self.kw_in_joyhub_post_page_get(**params)
        obj_log.info(f"获得岗位分页列表响应: {resp}")
        
        return resp

    @allure.step("获取岗位精简列表")
    def kw_joyhub_post_simple_list_get(self):
        """
        获取岗位精简列表业务关键字
        :return: 响应结果
        """
        obj_log.info("获取岗位精简列表")
        
        resp = self.kw_in_joyhub_post_simple_list_get()
        obj_log.info(f"获取岗位精简列表响应: {resp}")
        
        return resp

    @allure.step("修改岗位")
    def kw_joyhub_post_update_put(self, name, code, sort, status, post_id=None, remark=""):
        """
        修改岗位业务关键字
        :param name: 岗位名称
        :param code: 岗位编码
        :param sort: 显示顺序
        :param status: 状态
        :param post_id: 岗位编号（可选，更新时需要）
        :param remark: 备注
        :return: 响应结果
        """
        obj_log.info(f"修改岗位 - id: {post_id}, name: {name}, code: {code}, sort: {sort}, status: {status}, remark: {remark}")
        
        params = {
            "name": name,
            "code": code,
            "sort": sort,
            "status": status
        }
        
        if post_id:
            params["id"] = post_id
        if remark:
            params["remark"] = remark
        
        resp = self.kw_in_joyhub_post_update_put(**params)
        obj_log.info(f"修改岗位响应: {resp}")
        
        return resp
