package top.imwork.window.silos.convert;

import org.springframework.util.ObjectUtils;
import top.imwork.window.silos.entity.upms.SysUser;
import top.imwork.window.silos.pojo.bo.SysUserBO;
import top.imwork.window.silos.pojo.bo.SysUserResultBO;
import top.imwork.window.silos.pojo.dto.SysUserListDTO;
import top.imwork.window.silos.pojo.po.SysUserListParamVO;
import top.imwork.window.silos.pojo.po.SysUserParamVO;
import top.imwork.window.silos.pojo.vo.SysUserResultVO;
import top.imwork.window.silos.pojo.vo.SysUserVO;
import top.imwork.window.silos.pojo.dto.SysUserDTO;

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

/**
 * 用户信息
 * 实体转换
 *
 * @author jiangxiaowei
 * email: e-jiangxiaowei@outlook.com
 * date: 2025-12-09 16:29:22
 */
public class SysUserConvert {
    private SysUserConvert() {}

    public static SysUser sysUserDtoToDo(SysUserDTO sysUserDTO) {
        if (sysUserDTO == null) {
            return null;
        }
        SysUser sysUser = new SysUser();
        sysUser.setId(sysUserDTO.getId());
        sysUser.setLoginName(sysUserDTO.getLoginName());
        sysUser.setLoginPassword(sysUserDTO.getLoginPassword());
        sysUser.setSecondLoginPassword(sysUserDTO.getSecondLoginPassword());
        sysUser.setUserName(sysUserDTO.getUserName());
        sysUser.setUserNamePinyin(sysUserDTO.getUserNamePinyin());
        sysUser.setUserNameSpell(sysUserDTO.getUserNameSpell());
        sysUser.setUserGender(sysUserDTO.getUserGender());
        sysUser.setUserIdCard(sysUserDTO.getUserIdCard());
        sysUser.setUserEmail(sysUserDTO.getUserEmail());
        sysUser.setUserMobilePhone(sysUserDTO.getUserMobilePhone());
        sysUser.setUserAddress(sysUserDTO.getUserAddress());
        sysUser.setUserDesc(sysUserDTO.getUserDesc());
        sysUser.setUserType(sysUserDTO.getUserType());
        sysUser.setUserStatus(sysUserDTO.getUserStatus());
        sysUser.setUserAvatarId(sysUserDTO.getUserAvatarId());
        sysUser.setUserNickName(sysUserDTO.getUserNickName());
        sysUser.setSalt(sysUserDTO.getSalt());
        sysUser.setDncnet(sysUserDTO.getDncnet());
        sysUser.setAllowedErrorTimes(sysUserDTO.getAllowedErrorTimes());
        sysUser.setLoginErrorTimes(sysUserDTO.getLoginErrorTimes());
        sysUser.setIsDifferentIpLogin(sysUserDTO.getIsDifferentIpLogin());
        sysUser.setLastLoginTime(sysUserDTO.getLastLoginTime());
        sysUser.setEnabled(sysUserDTO.getEnabled());
        sysUser.setSort(sysUserDTO.getSort());
        sysUser.setState(sysUserDTO.getState());
        sysUser.setStatus(sysUserDTO.getStatus());
        sysUser.setDelFlag(sysUserDTO.getDelFlag());
        sysUser.setCreator(sysUserDTO.getCreator());
        sysUser.setCreateTime(sysUserDTO.getCreateTime());
        sysUser.setModifier(sysUserDTO.getModifier());
        sysUser.setUpdateTime(sysUserDTO.getUpdateTime());
        sysUser.setRemark(sysUserDTO.getRemark());
        return sysUser;
    }

    public static SysUserBO sysUserDoToBo(SysUser sysUser) {
        if (sysUser == null) {
            return null;
        }
        SysUserBO sysUserBO = new SysUserBO();
        sysUserBO.setId(sysUser.getId());
        sysUserBO.setLoginName(sysUser.getLoginName());
        sysUserBO.setLoginPassword(sysUser.getLoginPassword());
        sysUserBO.setSecondLoginPassword(sysUser.getSecondLoginPassword());
        sysUserBO.setUserName(sysUser.getUserName());
        sysUserBO.setUserNamePinyin(sysUser.getUserNamePinyin());
        sysUserBO.setUserNameSpell(sysUser.getUserNameSpell());
        sysUserBO.setUserGender(sysUser.getUserGender());
        sysUserBO.setUserIdCard(sysUser.getUserIdCard());
        sysUserBO.setUserEmail(sysUser.getUserEmail());
        sysUserBO.setUserMobilePhone(sysUser.getUserMobilePhone());
        sysUserBO.setUserAddress(sysUser.getUserAddress());
        sysUserBO.setUserDesc(sysUser.getUserDesc());
        sysUserBO.setUserType(sysUser.getUserType());
        sysUserBO.setUserStatus(sysUser.getUserStatus());
        sysUserBO.setUserAvatarId(sysUser.getUserAvatarId());
        sysUserBO.setUserNickName(sysUser.getUserNickName());
        sysUserBO.setSalt(sysUser.getSalt());
        sysUserBO.setDncnet(sysUser.getDncnet());
        sysUserBO.setAllowedErrorTimes(sysUser.getAllowedErrorTimes());
        sysUserBO.setLoginErrorTimes(sysUser.getLoginErrorTimes());
        sysUserBO.setIsDifferentIpLogin(sysUser.getIsDifferentIpLogin());
        sysUserBO.setLastLoginTime(sysUser.getLastLoginTime());
        sysUserBO.setEnabled(sysUser.getEnabled());
        sysUserBO.setSort(sysUser.getSort());
        sysUserBO.setState(sysUser.getState());
        sysUserBO.setStatus(sysUser.getStatus());
        sysUserBO.setDelFlag(sysUser.getDelFlag());
        sysUserBO.setCreator(sysUser.getCreator());
        sysUserBO.setCreateTime(sysUser.getCreateTime());
        sysUserBO.setModifier(sysUser.getModifier());
        sysUserBO.setUpdateTime(sysUser.getUpdateTime());
        sysUserBO.setRemark(sysUser.getRemark());
        return sysUserBO;
    }

    public static SysUserDTO sysUserParamVoToDto(SysUserParamVO sysUserParamVO) {
        if (sysUserParamVO == null) {
            return null;
        }
        SysUserDTO sysUserDTO = new SysUserDTO();
        sysUserDTO.setId(sysUserParamVO.getId());
        sysUserDTO.setLoginName(sysUserParamVO.getLoginName());
        sysUserDTO.setLoginPassword(sysUserParamVO.getLoginPassword());
        sysUserDTO.setSecondLoginPassword(sysUserParamVO.getSecondLoginPassword());
        sysUserDTO.setUserName(sysUserParamVO.getUserName());
        sysUserDTO.setUserNamePinyin(sysUserParamVO.getUserNamePinyin());
        sysUserDTO.setUserNameSpell(sysUserParamVO.getUserNameSpell());
        sysUserDTO.setUserGender(sysUserParamVO.getUserGender());
        sysUserDTO.setUserIdCard(sysUserParamVO.getUserIdCard());
        sysUserDTO.setUserEmail(sysUserParamVO.getUserEmail());
        sysUserDTO.setUserMobilePhone(sysUserParamVO.getUserMobilePhone());
        sysUserDTO.setUserAddress(sysUserParamVO.getUserAddress());
        sysUserDTO.setUserDesc(sysUserParamVO.getUserDesc());
        sysUserDTO.setUserType(sysUserParamVO.getUserType());
        sysUserDTO.setUserStatus(sysUserParamVO.getUserStatus());
        sysUserDTO.setUserAvatarId(sysUserParamVO.getUserAvatarId());
        sysUserDTO.setUserNickName(sysUserParamVO.getUserNickName());
        sysUserDTO.setSalt(sysUserParamVO.getSalt());
        sysUserDTO.setDncnet(sysUserParamVO.getDncnet());
        sysUserDTO.setAllowedErrorTimes(sysUserParamVO.getAllowedErrorTimes());
        sysUserDTO.setLoginErrorTimes(sysUserParamVO.getLoginErrorTimes());
        sysUserDTO.setIsDifferentIpLogin(sysUserParamVO.getIsDifferentIpLogin());
        sysUserDTO.setLastLoginTime(sysUserParamVO.getLastLoginTime());
        sysUserDTO.setEnabled(sysUserParamVO.getEnabled());
        sysUserDTO.setSort(sysUserParamVO.getSort());
        sysUserDTO.setState(sysUserParamVO.getState());
        sysUserDTO.setStatus(sysUserParamVO.getStatus());
        sysUserDTO.setDelFlag(sysUserParamVO.getDelFlag());
        sysUserDTO.setCreator(sysUserParamVO.getCreator());
        sysUserDTO.setCreateTime(sysUserParamVO.getCreateTime());
        sysUserDTO.setModifier(sysUserParamVO.getModifier());
        sysUserDTO.setUpdateTime(sysUserParamVO.getUpdateTime());
        sysUserDTO.setRemark(sysUserParamVO.getRemark());
        return sysUserDTO;
    }

    public static List<SysUserBO> sysUserListToSysUserBOList(List<SysUser> records) {
         if (ObjectUtils.isEmpty(records)) {
             return new ArrayList<>();
         }
         List<SysUserBO> sysUserBOList = new ArrayList<>();
         for (SysUser sysUser : records) {
             sysUserBOList.add(sysUserDoToBo(sysUser));
         }
         return sysUserBOList;
    }

    public static SysUserVO sysUserBoToVo(SysUserBO sysUserBO) {
        if (sysUserBO == null) {
            return null;
        }
        SysUserVO sysUserVO = new SysUserVO();
        sysUserVO.setId(sysUserBO.getId());
        sysUserVO.setLoginName(sysUserBO.getLoginName());
        sysUserVO.setLoginPassword(sysUserBO.getLoginPassword());
        sysUserVO.setSecondLoginPassword(sysUserBO.getSecondLoginPassword());
        sysUserVO.setUserName(sysUserBO.getUserName());
        sysUserVO.setUserNamePinyin(sysUserBO.getUserNamePinyin());
        sysUserVO.setUserNameSpell(sysUserBO.getUserNameSpell());
        sysUserVO.setUserGender(sysUserBO.getUserGender());
        sysUserVO.setUserIdCard(sysUserBO.getUserIdCard());
        sysUserVO.setUserEmail(sysUserBO.getUserEmail());
        sysUserVO.setUserMobilePhone(sysUserBO.getUserMobilePhone());
        sysUserVO.setUserAddress(sysUserBO.getUserAddress());
        sysUserVO.setUserDesc(sysUserBO.getUserDesc());
        sysUserVO.setUserType(sysUserBO.getUserType());
        sysUserVO.setUserStatus(sysUserBO.getUserStatus());
        sysUserVO.setUserAvatarId(sysUserBO.getUserAvatarId());
        sysUserVO.setUserNickName(sysUserBO.getUserNickName());
        sysUserVO.setSalt(sysUserBO.getSalt());
        sysUserVO.setDncnet(sysUserBO.getDncnet());
        sysUserVO.setAllowedErrorTimes(sysUserBO.getAllowedErrorTimes());
        sysUserVO.setLoginErrorTimes(sysUserBO.getLoginErrorTimes());
        sysUserVO.setIsDifferentIpLogin(sysUserBO.getIsDifferentIpLogin());
        sysUserVO.setLastLoginTime(sysUserBO.getLastLoginTime());
        sysUserVO.setEnabled(sysUserBO.getEnabled());
        sysUserVO.setSort(sysUserBO.getSort());
        sysUserVO.setState(sysUserBO.getState());
        sysUserVO.setStatus(sysUserBO.getStatus());
        sysUserVO.setDelFlag(sysUserBO.getDelFlag());
        sysUserVO.setCreator(sysUserBO.getCreator());
        sysUserVO.setCreateTime(sysUserBO.getCreateTime());
        sysUserVO.setModifier(sysUserBO.getModifier());
        sysUserVO.setUpdateTime(sysUserBO.getUpdateTime());
        sysUserVO.setRemark(sysUserBO.getRemark());
        return sysUserVO;
    }

    public static SysUserListDTO sysUserListParamVoToDTO(SysUserListParamVO sysUserListParamVO) {
        if (sysUserListParamVO == null) {
            return null;
        }
        SysUserListDTO sysUserListDTO = new SysUserListDTO();
        sysUserListDTO.setUserName(sysUserListParamVO.getUserName());
        sysUserListDTO.setLoginName(sysUserListParamVO.getLoginName());
        sysUserListDTO.setUserMobilePhone(sysUserListParamVO.getUserMobilePhone());
        sysUserListDTO.setUserNickName(sysUserListParamVO.getUserNickName());
        sysUserListDTO.setUserEmail(sysUserListParamVO.getUserEmail());
        sysUserListDTO.setUserIdCard(sysUserListParamVO.getUserIdCard());
        sysUserListDTO.setUserType(sysUserListParamVO.getUserType());
        sysUserListDTO.setUserStatus(sysUserListParamVO.getUserStatus());
        sysUserListDTO.setUserGender(sysUserListParamVO.getUserGender());
        sysUserListDTO.setDncnet(sysUserListParamVO.getDncnet());
        sysUserListDTO.setDelFlag(sysUserListParamVO.getDelFlag());
        sysUserListDTO.setPageNo(sysUserListParamVO.getPageNo());
        sysUserListDTO.setPageRows(sysUserListParamVO.getPageRows());
        sysUserListDTO.setDelFlag(sysUserListParamVO.getDelFlag());
        sysUserListDTO.setCreator(sysUserListParamVO.getCreator());
        sysUserListDTO.setCreateBeginTime(sysUserListParamVO.getCreateBeginTime());
        sysUserListDTO.setCreateEndTime(sysUserListParamVO.getCreateEndTime());
        sysUserListDTO.setModifier(sysUserListParamVO.getModifier());
        sysUserListDTO.setUpdateBeginTime(sysUserListParamVO.getUpdateBeginTime());
        sysUserListDTO.setUpdateEndTime(sysUserListParamVO.getUpdateEndTime());
        sysUserListDTO.setRemark(sysUserListParamVO.getRemark());
        return sysUserListDTO;
    }
        
    public static SysUserListParamVO sysUserListParamDtoToVo(SysUserListDTO sysUserListDTO) {
        if (sysUserListDTO == null) {
            return new SysUserListParamVO();
        }
        SysUserListParamVO sysUserListParamVO = new SysUserListParamVO();
        sysUserListParamVO.setUserName(sysUserListDTO.getUserName());
        sysUserListParamVO.setPageNo(sysUserListDTO.getPageNo());
        sysUserListParamVO.setPageRows(sysUserListDTO.getPageRows());
        sysUserListParamVO.setDelFlag(sysUserListDTO.getDelFlag());
        sysUserListParamVO.setCreator(sysUserListDTO.getCreator());
        sysUserListParamVO.setCreateBeginTime(sysUserListDTO.getCreateBeginTime());
        sysUserListParamVO.setCreateEndTime(sysUserListDTO.getCreateEndTime());
        sysUserListParamVO.setModifier(sysUserListDTO.getModifier());
        sysUserListParamVO.setUpdateBeginTime(sysUserListDTO.getUpdateBeginTime());
        sysUserListParamVO.setUpdateEndTime(sysUserListDTO.getUpdateEndTime());
        sysUserListParamVO.setRemark(sysUserListDTO.getRemark());
        return sysUserListParamVO;
    }

    private static List<SysUserVO> sysUserBoListToSysUserVoList(List<SysUserBO> dataList) {
        if (ObjectUtils.isEmpty(dataList)) {
            return new ArrayList<>();
        }
        List<SysUserVO> sysUserVOList = new ArrayList<>();
        for (SysUserBO sysUserBO : dataList) {
             sysUserVOList.add(sysUserBoToVo(sysUserBO));
        }
        return sysUserVOList;
    }

    public static SysUserResultVO sysUserResultBoToVo(SysUserResultBO sysUserResultBO) {
        if (sysUserResultBO == null) {
            return new SysUserResultVO();
        }
        SysUserResultVO sysUserResultVO = new SysUserResultVO();
        sysUserResultVO.setPageNo(sysUserResultBO.getPageNo());
        sysUserResultVO.setPageRows(sysUserResultBO.getPageRows());
        sysUserResultVO.setPageCount(sysUserResultBO.getPageCount());
        sysUserResultVO.setTotalRows(sysUserResultBO.getTotalRows());
        sysUserResultVO.setDataList(sysUserBoListToSysUserVoList(sysUserResultBO.getDataList()));
        sysUserResultVO.setParams(sysUserListParamDtoToVo(sysUserResultBO.getParams()));
        return sysUserResultVO;
    }
}