package top.imwork.window.silos.convert.upms;

import org.springframework.util.ObjectUtils;
import top.imwork.window.silos.entity.upms.Permission;
import top.imwork.window.silos.pojo.upms.bo.PermissionBO;
import top.imwork.window.silos.pojo.upms.bo.PermissionResultBO;
import top.imwork.window.silos.pojo.upms.dto.PermissionDTO;
import top.imwork.window.silos.pojo.upms.dto.PermissionListDTO;
import top.imwork.window.silos.pojo.upms.po.PermissionListParamVO;
import top.imwork.window.silos.pojo.upms.po.PermissionParamVO;
import top.imwork.window.silos.pojo.upms.vo.PermissionResultVO;
import top.imwork.window.silos.pojo.upms.vo.PermissionVO;

import java.util.ArrayList;
import java.util.List;

/**
 * 权限信息
 * 实体转换
 *
 * @author jiangxiaowei
 * email: e-jiangxiaowei@outlook.com
 * date: 2025-12-11 12:21:32
 */
public class PermissionConvert {
    private PermissionConvert() {}

    public static Permission permissionDtoToDo(PermissionDTO permissionDTO) {
        if (permissionDTO == null) {
            return null;
        }
        Permission permission = new Permission();
        permission.setId(permissionDTO.getId());
        permission.setAuthCode(permissionDTO.getAuthCode());
        permission.setAuthName(permissionDTO.getAuthName());
        permission.setAuthType(permissionDTO.getAuthType());
        permission.setAuthLevel(permissionDTO.getAuthLevel());
        permission.setParentId(permissionDTO.getParentId());
        permission.setParentIds(permissionDTO.getParentIds());
        permission.setParentAuthName(permissionDTO.getParentAuthName());
        permission.setPrivilegeCode(permissionDTO.getPrivilegeCode());
        permission.setPrivilegeName(permissionDTO.getPrivilegeName());
        permission.setPrivilegeType(permissionDTO.getPrivilegeType());
        permission.setPrivilegeLevel(permissionDTO.getPrivilegeLevel());
        permission.setPrivilegeIconsId(permissionDTO.getPrivilegeIconsId());
        permission.setPrivilegeState(permissionDTO.getPrivilegeState());
        permission.setPrivilegeStatus(permissionDTO.getPrivilegeStatus());
        permission.setSort(permissionDTO.getSort());
        permission.setState(permissionDTO.getState());
        permission.setStatus(permissionDTO.getStatus());
        permission.setDelFlag(permissionDTO.getDelFlag());
        permission.setCreator(permissionDTO.getCreator());
        permission.setCreateTime(permissionDTO.getCreateTime());
        permission.setModifier(permissionDTO.getModifier());
        permission.setUpdateTime(permissionDTO.getUpdateTime());
        permission.setRemark(permissionDTO.getRemark());
        return permission;
    }

    public static PermissionBO permissionDoToBo(Permission permission) {
        if (permission == null) {
            return null;
        }
        PermissionBO permissionBO = new PermissionBO();
        permissionBO.setId(permission.getId());
        permissionBO.setAuthCode(permission.getAuthCode());
        permissionBO.setAuthName(permission.getAuthName());
        permissionBO.setAuthType(permission.getAuthType());
        permissionBO.setAuthLevel(permission.getAuthLevel());
        permissionBO.setParentId(permission.getParentId());
        permissionBO.setParentIds(permission.getParentIds());
        permissionBO.setParentAuthName(permission.getParentAuthName());
        permissionBO.setPrivilegeCode(permission.getPrivilegeCode());
        permissionBO.setPrivilegeName(permission.getPrivilegeName());
        permissionBO.setPrivilegeType(permission.getPrivilegeType());
        permissionBO.setPrivilegeLevel(permission.getPrivilegeLevel());
        permissionBO.setPrivilegeIconsId(permission.getPrivilegeIconsId());
        permissionBO.setPrivilegeState(permission.getPrivilegeState());
        permissionBO.setPrivilegeStatus(permission.getPrivilegeStatus());
        permissionBO.setSort(permission.getSort());
        permissionBO.setState(permission.getState());
        permissionBO.setStatus(permission.getStatus());
        permissionBO.setDelFlag(permission.getDelFlag());
        permissionBO.setCreator(permission.getCreator());
        permissionBO.setCreateTime(permission.getCreateTime());
        permissionBO.setModifier(permission.getModifier());
        permissionBO.setUpdateTime(permission.getUpdateTime());
        permissionBO.setRemark(permission.getRemark());
        return permissionBO;
    }

    public static PermissionDTO permissionParamVoToDto(PermissionParamVO permissionParamVO) {
        if (permissionParamVO == null) {
            return null;
        }
        PermissionDTO permissionDTO = new PermissionDTO();
        permissionDTO.setId(permissionParamVO.getId());
        permissionDTO.setAuthCode(permissionParamVO.getAuthCode());
        permissionDTO.setAuthName(permissionParamVO.getAuthName());
        permissionDTO.setAuthType(permissionParamVO.getAuthType());
        permissionDTO.setAuthLevel(permissionParamVO.getAuthLevel());
        permissionDTO.setParentId(permissionParamVO.getParentId());
        permissionDTO.setParentIds(permissionParamVO.getParentIds());
        permissionDTO.setParentAuthName(permissionParamVO.getParentAuthName());
        permissionDTO.setPrivilegeCode(permissionParamVO.getPrivilegeCode());
        permissionDTO.setPrivilegeName(permissionParamVO.getPrivilegeName());
        permissionDTO.setPrivilegeType(permissionParamVO.getPrivilegeType());
        permissionDTO.setPrivilegeLevel(permissionParamVO.getPrivilegeLevel());
        permissionDTO.setPrivilegeIconsId(permissionParamVO.getPrivilegeIconsId());
        permissionDTO.setPrivilegeState(permissionParamVO.getPrivilegeState());
        permissionDTO.setPrivilegeStatus(permissionParamVO.getPrivilegeStatus());
        permissionDTO.setSort(permissionParamVO.getSort());
        permissionDTO.setState(permissionParamVO.getState());
        permissionDTO.setStatus(permissionParamVO.getStatus());
        permissionDTO.setDelFlag(permissionParamVO.getDelFlag());
        permissionDTO.setCreator(permissionParamVO.getCreator());
        permissionDTO.setCreateTime(permissionParamVO.getCreateTime());
        permissionDTO.setModifier(permissionParamVO.getModifier());
        permissionDTO.setUpdateTime(permissionParamVO.getUpdateTime());
        permissionDTO.setRemark(permissionParamVO.getRemark());
        return permissionDTO;
    }

    public static List<PermissionBO> permissionListToPermissionBOList(List<Permission> records) {
         if (ObjectUtils.isEmpty(records)) {
             return new ArrayList<>();
         }
         List<PermissionBO> permissionBOList = new ArrayList<>();
         for (Permission permission : records) {
             permissionBOList.add(permissionDoToBo(permission));
         }
         return permissionBOList;
    }

    public static PermissionVO permissionBoToVo(PermissionBO permissionBO) {
        if (permissionBO == null) {
            return null;
        }
        PermissionVO permissionVO = new PermissionVO();
        permissionVO.setId(permissionBO.getId());
        permissionVO.setAuthCode(permissionBO.getAuthCode());
        permissionVO.setAuthName(permissionBO.getAuthName());
        permissionVO.setAuthType(permissionBO.getAuthType());
        permissionVO.setAuthLevel(permissionBO.getAuthLevel());
        permissionVO.setParentId(permissionBO.getParentId());
        permissionVO.setParentIds(permissionBO.getParentIds());
        permissionVO.setParentAuthName(permissionBO.getParentAuthName());
        permissionVO.setPrivilegeCode(permissionBO.getPrivilegeCode());
        permissionVO.setPrivilegeName(permissionBO.getPrivilegeName());
        permissionVO.setPrivilegeType(permissionBO.getPrivilegeType());
        permissionVO.setPrivilegeLevel(permissionBO.getPrivilegeLevel());
        permissionVO.setPrivilegeIconsId(permissionBO.getPrivilegeIconsId());
        permissionVO.setPrivilegeState(permissionBO.getPrivilegeState());
        permissionVO.setPrivilegeStatus(permissionBO.getPrivilegeStatus());
        permissionVO.setSort(permissionBO.getSort());
        permissionVO.setState(permissionBO.getState());
        permissionVO.setStatus(permissionBO.getStatus());
        permissionVO.setDelFlag(permissionBO.getDelFlag());
        permissionVO.setCreator(permissionBO.getCreator());
        permissionVO.setCreateTime(permissionBO.getCreateTime());
        permissionVO.setModifier(permissionBO.getModifier());
        permissionVO.setUpdateTime(permissionBO.getUpdateTime());
        permissionVO.setRemark(permissionBO.getRemark());
        return permissionVO;
    }

    public static PermissionListDTO permissionListParamVoToDTO(PermissionListParamVO permissionListParamVO) {
        if (permissionListParamVO == null) {
            return new PermissionListDTO();
        }
        PermissionListDTO permissionListDTO = new PermissionListDTO();
        permissionListDTO.setPermissionName(permissionListParamVO.getPermissionName());
        permissionListDTO.setPageNo(permissionListParamVO.getPageNo());
        permissionListDTO.setPageRows(permissionListParamVO.getPageRows());
        permissionListDTO.setDelFlag(permissionListParamVO.getDelFlag());
        permissionListDTO.setCreator(permissionListParamVO.getCreator());
        permissionListDTO.setCreateBeginTime(permissionListParamVO.getCreateBeginTime());
        permissionListDTO.setCreateEndTime(permissionListParamVO.getCreateEndTime());
        permissionListDTO.setModifier(permissionListParamVO.getModifier());
        permissionListDTO.setUpdateBeginTime(permissionListParamVO.getUpdateBeginTime());
        permissionListDTO.setUpdateEndTime(permissionListParamVO.getUpdateEndTime());
        permissionListDTO.setRemark(permissionListParamVO.getRemark());
        return permissionListDTO;
    }
        
    public static PermissionListParamVO permissionListParamDtoToVo(PermissionListDTO permissionListDTO) {
        if (permissionListDTO == null) {
            return new PermissionListParamVO();
        }
        PermissionListParamVO permissionListParamVO = new PermissionListParamVO();
        permissionListParamVO.setPermissionName(permissionListDTO.getPermissionName());
        permissionListParamVO.setPageNo(permissionListDTO.getPageNo());
        permissionListParamVO.setPageRows(permissionListDTO.getPageRows());
        permissionListParamVO.setDelFlag(permissionListDTO.getDelFlag());
        permissionListParamVO.setCreator(permissionListDTO.getCreator());
        permissionListParamVO.setCreateBeginTime(permissionListDTO.getCreateBeginTime());
        permissionListParamVO.setCreateEndTime(permissionListDTO.getCreateEndTime());
        permissionListParamVO.setModifier(permissionListDTO.getModifier());
        permissionListParamVO.setUpdateBeginTime(permissionListDTO.getUpdateBeginTime());
        permissionListParamVO.setUpdateEndTime(permissionListDTO.getUpdateEndTime());
        permissionListParamVO.setRemark(permissionListDTO.getRemark());
        return permissionListParamVO;
    }

    private static List<PermissionVO> permissionBoListToPermissionVoList(List<PermissionBO> dataList) {
        if (ObjectUtils.isEmpty(dataList)) {
            return new ArrayList<>();
        }
        List<PermissionVO> permissionVOList = new ArrayList<>();
        for (PermissionBO permissionBO : dataList) {
             permissionVOList.add(permissionBoToVo(permissionBO));
        }
        return permissionVOList;
    }

    public static PermissionResultVO permissionResultBoToVo(PermissionResultBO permissionResultBO) {
        if (permissionResultBO == null) {
            return new PermissionResultVO();
        }
        PermissionResultVO permissionResultVO = new PermissionResultVO();
        permissionResultVO.setPageNo(permissionResultBO.getPageNo());
        permissionResultVO.setPageRows(permissionResultBO.getPageRows());
        permissionResultVO.setPageCount(permissionResultBO.getPageCount());
        permissionResultVO.setTotalRows(permissionResultBO.getTotalRows());
        permissionResultVO.setDataList(permissionBoListToPermissionVoList(permissionResultBO.getDataList()));
        permissionResultVO.setParams(permissionListParamDtoToVo(permissionResultBO.getParams()));
        return permissionResultVO;
    }
}