package top.imwork.window.silos.convert;

import org.springframework.util.ObjectUtils;
import top.imwork.window.silos.entity.upms.SysUserRole;
import top.imwork.window.silos.pojo.bo.SysUserRoleBO;
import top.imwork.window.silos.pojo.bo.SysUserRoleResultBO;
import top.imwork.window.silos.pojo.dto.SysUserRoleListDTO;
import top.imwork.window.silos.pojo.po.SysUserRoleListParamVO;
import top.imwork.window.silos.pojo.po.SysUserRoleParamVO;
import top.imwork.window.silos.pojo.vo.SysUserRoleResultVO;
import top.imwork.window.silos.pojo.vo.SysUserRoleVO;
import top.imwork.window.silos.pojo.dto.SysUserRoleDTO;

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

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

    public static SysUserRole sysUserRoleDtoToDo(SysUserRoleDTO sysUserRoleDTO) {
        if (sysUserRoleDTO == null) {
            return null;
        }
        SysUserRole sysUserRole = new SysUserRole();
        sysUserRole.setId(sysUserRoleDTO.getId());
        sysUserRole.setUserId(sysUserRoleDTO.getUserId());
        sysUserRole.setRoleId(sysUserRoleDTO.getRoleId());
        sysUserRole.setCreator(sysUserRoleDTO.getCreator());
        sysUserRole.setCreateTime(sysUserRoleDTO.getCreateTime());
        return sysUserRole;
    }

    public static SysUserRoleBO sysUserRoleDoToBo(SysUserRole sysUserRole) {
        if (sysUserRole == null) {
            return null;
        }
        SysUserRoleBO sysUserRoleBO = new SysUserRoleBO();
        sysUserRoleBO.setId(sysUserRole.getId());
        sysUserRoleBO.setUserId(sysUserRole.getUserId());
        sysUserRoleBO.setRoleId(sysUserRole.getRoleId());
        sysUserRoleBO.setCreator(sysUserRole.getCreator());
        sysUserRoleBO.setCreateTime(sysUserRole.getCreateTime());
        return sysUserRoleBO;
    }

    public static SysUserRoleDTO sysUserRoleParamVoToDto(SysUserRoleParamVO sysUserRoleParamVO) {
        if (sysUserRoleParamVO == null) {
            return null;
        }
        SysUserRoleDTO sysUserRoleDTO = new SysUserRoleDTO();
        sysUserRoleDTO.setId(sysUserRoleParamVO.getId());
        sysUserRoleDTO.setUserId(sysUserRoleParamVO.getUserId());
        sysUserRoleDTO.setRoleId(sysUserRoleParamVO.getRoleId());
        sysUserRoleDTO.setRolesId(sysUserRoleParamVO.getRolesId());
        sysUserRoleDTO.setCreator(sysUserRoleParamVO.getCreator());
        sysUserRoleDTO.setCreateTime(sysUserRoleParamVO.getCreateTime());
        return sysUserRoleDTO;
    }

    public static List<SysUserRoleBO> sysUserRoleListToSysUserRoleBOList(List<SysUserRole> records) {
         if (ObjectUtils.isEmpty(records)) {
             return new ArrayList<>();
         }
         List<SysUserRoleBO> sysUserRoleBOList = new ArrayList<>();
         for (SysUserRole sysUserRole : records) {
             sysUserRoleBOList.add(sysUserRoleDoToBo(sysUserRole));
         }
         return sysUserRoleBOList;
    }

    public static SysUserRoleVO sysUserRoleBoToVo(SysUserRoleBO sysUserRoleBO) {
        if (sysUserRoleBO == null) {
            return null;
        }
        SysUserRoleVO sysUserRoleVO = new SysUserRoleVO();
        sysUserRoleVO.setId(sysUserRoleBO.getId());
        sysUserRoleVO.setUserId(sysUserRoleBO.getUserId());
        sysUserRoleVO.setRoleId(sysUserRoleBO.getRoleId());
        sysUserRoleVO.setCreator(sysUserRoleBO.getCreator());
        sysUserRoleVO.setCreateTime(sysUserRoleBO.getCreateTime());
        return sysUserRoleVO;
    }

    public static SysUserRoleListDTO sysUserRoleListParamVoToDTO(SysUserRoleListParamVO sysUserRoleListParamVO) {
        if (sysUserRoleListParamVO == null) {
            return new SysUserRoleListDTO();
        }
        SysUserRoleListDTO sysUserRoleListDTO = new SysUserRoleListDTO();
        sysUserRoleListDTO.setSysUserRoleName(sysUserRoleListParamVO.getSysUserRoleName());
        sysUserRoleListDTO.setPageNo(sysUserRoleListParamVO.getPageNo());
        sysUserRoleListDTO.setPageRows(sysUserRoleListParamVO.getPageRows());
        sysUserRoleListDTO.setDelFlag(sysUserRoleListParamVO.getDelFlag());
        sysUserRoleListDTO.setCreator(sysUserRoleListParamVO.getCreator());
        sysUserRoleListDTO.setCreateBeginTime(sysUserRoleListParamVO.getCreateBeginTime());
        sysUserRoleListDTO.setCreateEndTime(sysUserRoleListParamVO.getCreateEndTime());
        sysUserRoleListDTO.setModifier(sysUserRoleListParamVO.getModifier());
        sysUserRoleListDTO.setUpdateBeginTime(sysUserRoleListParamVO.getUpdateBeginTime());
        sysUserRoleListDTO.setUpdateEndTime(sysUserRoleListParamVO.getUpdateEndTime());
        sysUserRoleListDTO.setRemark(sysUserRoleListParamVO.getRemark());
        return sysUserRoleListDTO;
    }
        
    public static SysUserRoleListParamVO sysUserRoleListParamDtoToVo(SysUserRoleListDTO sysUserRoleListDTO) {
        if (sysUserRoleListDTO == null) {
            return new SysUserRoleListParamVO();
        }
        SysUserRoleListParamVO sysUserRoleListParamVO = new SysUserRoleListParamVO();
        sysUserRoleListParamVO.setSysUserRoleName(sysUserRoleListDTO.getSysUserRoleName());
        sysUserRoleListParamVO.setPageNo(sysUserRoleListDTO.getPageNo());
        sysUserRoleListParamVO.setPageRows(sysUserRoleListDTO.getPageRows());
        sysUserRoleListParamVO.setDelFlag(sysUserRoleListDTO.getDelFlag());
        sysUserRoleListParamVO.setCreator(sysUserRoleListDTO.getCreator());
        sysUserRoleListParamVO.setCreateBeginTime(sysUserRoleListDTO.getCreateBeginTime());
        sysUserRoleListParamVO.setCreateEndTime(sysUserRoleListDTO.getCreateEndTime());
        sysUserRoleListParamVO.setModifier(sysUserRoleListDTO.getModifier());
        sysUserRoleListParamVO.setUpdateBeginTime(sysUserRoleListDTO.getUpdateBeginTime());
        sysUserRoleListParamVO.setUpdateEndTime(sysUserRoleListDTO.getUpdateEndTime());
        sysUserRoleListParamVO.setRemark(sysUserRoleListDTO.getRemark());
        return sysUserRoleListParamVO;
    }

    private static List<SysUserRoleVO> sysUserRoleBoListToSysUserRoleVoList(List<SysUserRoleBO> dataList) {
        if (ObjectUtils.isEmpty(dataList)) {
            return new ArrayList<>();
        }
        List<SysUserRoleVO> sysUserRoleVOList = new ArrayList<>();
        for (SysUserRoleBO sysUserRoleBO : dataList) {
             sysUserRoleVOList.add(sysUserRoleBoToVo(sysUserRoleBO));
        }
        return sysUserRoleVOList;
    }

    public static SysUserRoleResultVO sysUserRoleResultBoToVo(SysUserRoleResultBO sysUserRoleResultBO) {
        if (sysUserRoleResultBO == null) {
            return new SysUserRoleResultVO();
        }
        SysUserRoleResultVO sysUserRoleResultVO = new SysUserRoleResultVO();
        sysUserRoleResultVO.setPageNo(sysUserRoleResultBO.getPageNo());
        sysUserRoleResultVO.setPageRows(sysUserRoleResultBO.getPageRows());
        sysUserRoleResultVO.setPageCount(sysUserRoleResultBO.getPageCount());
        sysUserRoleResultVO.setTotalRows(sysUserRoleResultBO.getTotalRows());
        sysUserRoleResultVO.setDataList(sysUserRoleBoListToSysUserRoleVoList(sysUserRoleResultBO.getDataList()));
        sysUserRoleResultVO.setParams(sysUserRoleListParamDtoToVo(sysUserRoleResultBO.getParams()));
        return sysUserRoleResultVO;
    }
}