package top.imwork.window.silos.convert;

import org.springframework.util.ObjectUtils;
import top.imwork.window.silos.entity.Contents;
import top.imwork.window.silos.pojo.bo.ContentsBO;
import top.imwork.window.silos.pojo.bo.ContentsResultBO;
import top.imwork.window.silos.pojo.dto.ContentsListDTO;
import top.imwork.window.silos.pojo.po.ContentsListParamVO;
import top.imwork.window.silos.pojo.po.ContentsParamVO;
import top.imwork.window.silos.pojo.vo.ContentsResultVO;
import top.imwork.window.silos.pojo.vo.ContentsVO;
import top.imwork.window.silos.pojo.dto.ContentsDTO;

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

/**
 * 图书内容表
 * 实体转换
 *
 * @author jiangxiaowei
 * email: e-jiangxiaowei@outlook.com
 * date: 2025-11-04 17:46:32
 */
public class ContentsConvert {
    private ContentsConvert() {}

    public static Contents contentsDtoToDo(ContentsDTO contentsDTO) {
        if (contentsDTO == null) {
            return null;
        }
        Contents contents = new Contents();
        contents.setId(contentsDTO.getId());
        contents.setBookInfoId(contentsDTO.getBookInfoId());
        contents.setParentId(contentsDTO.getParentId());
        contents.setChapterLevel(contentsDTO.getChapterLevel());
        contents.setChapterNumber(contentsDTO.getChapterNumber());
        contents.setChapterTitle(contentsDTO.getChapterTitle());
        contents.setPageNumber(contentsDTO.getPageNumber());
        contents.setContentType(contentsDTO.getContentType());
        contents.setContentText(contentsDTO.getContentText());
        contents.setContentHtml(contentsDTO.getContentHtml());
        contents.setMediaUrl(contentsDTO.getMediaUrl());
        contents.setWordCount(contentsDTO.getWordCount());
        contents.setReadingTime(contentsDTO.getReadingTime());
        contents.setSortOrder(contentsDTO.getSortOrder());
        contents.setIsPublic(contentsDTO.getIsPublic());
        contents.setHasChildren(contentsDTO.getHasChildren());
        contents.setVersion(contentsDTO.getVersion());
        contents.setDelFlag(contentsDTO.getDelFlag());
        contents.setCreator(contentsDTO.getCreator());
        contents.setCreateTime(contentsDTO.getCreateTime());
        contents.setModifier(contentsDTO.getModifier());
        contents.setUpdateTime(contentsDTO.getUpdateTime());
        contents.setRemark(contentsDTO.getRemark());
        return contents;
    }

    public static ContentsBO contentsDoToBo(Contents contents) {
        if (contents == null) {
            return null;
        }
        ContentsBO contentsBO = new ContentsBO();
        contentsBO.setId(contents.getId());
        contentsBO.setBookInfoId(contents.getBookInfoId());
        contentsBO.setParentId(contents.getParentId());
        contentsBO.setChapterLevel(contents.getChapterLevel());
        contentsBO.setChapterNumber(contents.getChapterNumber());
        contentsBO.setChapterTitle(contents.getChapterTitle());
        contentsBO.setPageNumber(contents.getPageNumber());
        contentsBO.setContentType(contents.getContentType());
        contentsBO.setContentText(contents.getContentText());
        contentsBO.setContentHtml(contents.getContentHtml());
        contentsBO.setMediaUrl(contents.getMediaUrl());
        contentsBO.setWordCount(contents.getWordCount());
        contentsBO.setReadingTime(contents.getReadingTime());
        contentsBO.setSortOrder(contents.getSortOrder());
        contentsBO.setIsPublic(contents.getIsPublic());
        contentsBO.setHasChildren(contents.getHasChildren());
        contentsBO.setVersion(contents.getVersion());
        contentsBO.setDelFlag(contents.getDelFlag());
        contentsBO.setCreator(contents.getCreator());
        contentsBO.setCreateTime(contents.getCreateTime());
        contentsBO.setModifier(contents.getModifier());
        contentsBO.setUpdateTime(contents.getUpdateTime());
        contentsBO.setRemark(contents.getRemark());
        return contentsBO;
    }

    public static ContentsDTO contentsParamVoToDto(ContentsParamVO contentsParamVO) {
        if (contentsParamVO == null) {
            return null;
        }
        ContentsDTO contentsDTO = new ContentsDTO();
        contentsDTO.setId(contentsParamVO.getId());
        contentsDTO.setBookInfoId(contentsParamVO.getBookInfoId());
        contentsDTO.setParentId(contentsParamVO.getParentId());
        contentsDTO.setChapterLevel(contentsParamVO.getChapterLevel());
        contentsDTO.setChapterNumber(contentsParamVO.getChapterNumber());
        contentsDTO.setChapterTitle(contentsParamVO.getChapterTitle());
        contentsDTO.setPageNumber(contentsParamVO.getPageNumber());
        contentsDTO.setContentType(contentsParamVO.getContentType());
        contentsDTO.setContentText(contentsParamVO.getContentText());
        contentsDTO.setContentHtml(contentsParamVO.getContentHtml());
        contentsDTO.setMediaUrl(contentsParamVO.getMediaUrl());
        contentsDTO.setWordCount(contentsParamVO.getWordCount());
        contentsDTO.setReadingTime(contentsParamVO.getReadingTime());
        contentsDTO.setSortOrder(contentsParamVO.getSortOrder());
        contentsDTO.setIsPublic(contentsParamVO.getIsPublic());
        contentsDTO.setHasChildren(contentsParamVO.getHasChildren());
        contentsDTO.setVersion(contentsParamVO.getVersion());
        contentsDTO.setDelFlag(contentsParamVO.getDelFlag());
        contentsDTO.setCreator(contentsParamVO.getCreator());
        contentsDTO.setCreateTime(contentsParamVO.getCreateTime());
        contentsDTO.setModifier(contentsParamVO.getModifier());
        contentsDTO.setUpdateTime(contentsParamVO.getUpdateTime());
        contentsDTO.setRemark(contentsParamVO.getRemark());
        return contentsDTO;
    }

    public static List<ContentsBO> contentsListToContentsBOList(List<Contents> records) {
         if (ObjectUtils.isEmpty(records)) {
             return new ArrayList<>();
         }
         List<ContentsBO> contentsBOList = new ArrayList<>();
         for (Contents contents : records) {
             contentsBOList.add(contentsDoToBo(contents));
         }
         return contentsBOList;
    }

    public static ContentsVO contentsBoToVo(ContentsBO contentsBO) {
        if (contentsBO == null) {
            return null;
        }
        ContentsVO contentsVO = new ContentsVO();
        contentsVO.setId(contentsBO.getId());
        contentsVO.setBookInfoId(contentsBO.getBookInfoId());
        contentsVO.setParentId(contentsBO.getParentId());
        contentsVO.setChapterLevel(contentsBO.getChapterLevel());
        contentsVO.setChapterNumber(contentsBO.getChapterNumber());
        contentsVO.setChapterTitle(contentsBO.getChapterTitle());
        contentsVO.setPageNumber(contentsBO.getPageNumber());
        contentsVO.setContentType(contentsBO.getContentType());
        contentsVO.setContentText(contentsBO.getContentText());
        contentsVO.setContentHtml(contentsBO.getContentHtml());
        contentsVO.setMediaUrl(contentsBO.getMediaUrl());
        contentsVO.setWordCount(contentsBO.getWordCount());
        contentsVO.setReadingTime(contentsBO.getReadingTime());
        contentsVO.setSortOrder(contentsBO.getSortOrder());
        contentsVO.setIsPublic(contentsBO.getIsPublic());
        contentsVO.setHasChildren(contentsBO.getHasChildren());
        contentsVO.setVersion(contentsBO.getVersion());
        contentsVO.setDelFlag(contentsBO.getDelFlag());
        contentsVO.setCreator(contentsBO.getCreator());
        contentsVO.setCreateTime(contentsBO.getCreateTime());
        contentsVO.setModifier(contentsBO.getModifier());
        contentsVO.setUpdateTime(contentsBO.getUpdateTime());
        contentsVO.setRemark(contentsBO.getRemark());
        return contentsVO;
    }

    public static ContentsListDTO contentsListParamVoToDTO(ContentsListParamVO contentsListParamVO) {
        if (contentsListParamVO == null) {
            return null;
        }
        ContentsListDTO contentsListDTO = new ContentsListDTO();
        contentsListDTO.setContentsName(contentsListParamVO.getContentsName());
        contentsListDTO.setBookInfoId(contentsListParamVO.getBookInfoId());
        contentsListDTO.setContentType(contentsListParamVO.getContentType());
        contentsListDTO.setIsPublic(contentsListParamVO.getIsPublic());
        contentsListDTO.setVersion(contentsListParamVO.getVersion());
        contentsListDTO.setCreateBeginTime(contentsListParamVO.getCreateBeginTime());
        contentsListDTO.setPageNo(contentsListParamVO.getPageNo());
        contentsListDTO.setPageRows(contentsListParamVO.getPageRows());
        contentsListDTO.setDelFlag(contentsListParamVO.getDelFlag());
        contentsListDTO.setCreator(contentsListParamVO.getCreator());
        contentsListDTO.setCreateBeginTime(contentsListParamVO.getCreateBeginTime());
        contentsListDTO.setCreateEndTime(contentsListParamVO.getCreateEndTime());
        contentsListDTO.setModifier(contentsListParamVO.getModifier());
        contentsListDTO.setUpdateBeginTime(contentsListParamVO.getUpdateBeginTime());
        contentsListDTO.setUpdateEndTime(contentsListParamVO.getUpdateEndTime());
        contentsListDTO.setRemark(contentsListParamVO.getRemark());
        return contentsListDTO;
    }
        
    public static ContentsListParamVO contentsListParamDtoToVo(ContentsListDTO contentsListDTO) {
        if (contentsListDTO == null) {
            return new ContentsListParamVO();
        }
        ContentsListParamVO contentsListParamVO = new ContentsListParamVO();
        contentsListParamVO.setContentsName(contentsListDTO.getContentsName());
        contentsListParamVO.setPageNo(contentsListDTO.getPageNo());
        contentsListParamVO.setPageRows(contentsListDTO.getPageRows());
        contentsListParamVO.setDelFlag(contentsListDTO.getDelFlag());
        contentsListParamVO.setCreator(contentsListDTO.getCreator());
        contentsListParamVO.setCreateBeginTime(contentsListDTO.getCreateBeginTime());
        contentsListParamVO.setCreateEndTime(contentsListDTO.getCreateEndTime());
        contentsListParamVO.setModifier(contentsListDTO.getModifier());
        contentsListParamVO.setUpdateBeginTime(contentsListDTO.getUpdateBeginTime());
        contentsListParamVO.setUpdateEndTime(contentsListDTO.getUpdateEndTime());
        contentsListParamVO.setRemark(contentsListDTO.getRemark());
        return contentsListParamVO;
    }

    private static List<ContentsVO> contentsBoListToContentsVoList(List<ContentsBO> dataList) {
        if (ObjectUtils.isEmpty(dataList)) {
            return new ArrayList<>();
        }
        List<ContentsVO> contentsVOList = new ArrayList<>();
        for (ContentsBO contentsBO : dataList) {
             contentsVOList.add(contentsBoToVo(contentsBO));
        }
        return contentsVOList;
    }

    public static ContentsResultVO contentsResultBoToVo(ContentsResultBO contentsResultBO) {
        if (contentsResultBO == null) {
            return new ContentsResultVO();
        }
        ContentsResultVO contentsResultVO = new ContentsResultVO();
        contentsResultVO.setPageNo(contentsResultBO.getPageNo());
        contentsResultVO.setPageRows(contentsResultBO.getPageRows());
        contentsResultVO.setPageCount(contentsResultBO.getPageCount());
        contentsResultVO.setTotalRows(contentsResultBO.getTotalRows());
        contentsResultVO.setDataList(contentsBoListToContentsVoList(contentsResultBO.getDataList()));
        contentsResultVO.setParams(contentsListParamDtoToVo(contentsResultBO.getParams()));
        return contentsResultVO;
    }
}