package top.imwork.window.silos.convert;

import org.springframework.util.ObjectUtils;
import top.imwork.window.silos.entity.Info;
import top.imwork.window.silos.pojo.bo.InfoBO;
import top.imwork.window.silos.pojo.bo.InfoResultBO;
import top.imwork.window.silos.pojo.dto.InfoListDTO;
import top.imwork.window.silos.pojo.po.InfoListParamVO;
import top.imwork.window.silos.pojo.po.InfoParamVO;
import top.imwork.window.silos.pojo.vo.InfoResultVO;
import top.imwork.window.silos.pojo.vo.InfoVO;
import top.imwork.window.silos.pojo.dto.InfoDTO;

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

/**
 * 图书信息表（书目数据）
 * 实体转换
 *
 * @author jiangxiaowei
 * email: e-jiangxiaowei@outlook.com
 * date: 2025-11-04 13:16:26
 */
public class InfoConvert {
    private InfoConvert() {}

    public static Info infoDtoToDo(InfoDTO infoDTO) {
        if (infoDTO == null) {
            return null;
        }
        Info info = new Info();
        info.setId(infoDTO.getId());
        info.setIsbn(infoDTO.getIsbn());
        info.setTitle(infoDTO.getTitle());
        info.setSubtitle(infoDTO.getSubtitle());
        info.setAuthor(infoDTO.getAuthor());
        info.setOtherAuthors(infoDTO.getOtherAuthors());
        info.setPublisher(infoDTO.getPublisher());
        info.setPublishDate(infoDTO.getPublishDate());
        info.setEdition(infoDTO.getEdition());
        info.setCategoryCode(infoDTO.getCategoryCode());
        info.setLanguage(infoDTO.getLanguage());
        info.setCoverImage(infoDTO.getCoverImage());
        info.setSummary(infoDTO.getSummary());
        info.setToc(infoDTO.getToc());
        info.setPrice(infoDTO.getPrice());
        info.setPages(infoDTO.getPages());
        info.setDimensions(infoDTO.getDimensions());
        info.setBinding(infoDTO.getBinding());
        info.setSeries(infoDTO.getSeries());
        info.setSource(infoDTO.getSource());
        info.setCreatedAt(infoDTO.getCreatedAt());
        info.setUpdatedAt(infoDTO.getUpdatedAt());
        return info;
    }

    public static InfoBO infoDoToBo(Info info) {
        if (info == null) {
            return null;
        }
        InfoBO infoBO = new InfoBO();
        infoBO.setId(info.getId());
        infoBO.setIsbn(info.getIsbn());
        infoBO.setTitle(info.getTitle());
        infoBO.setSubtitle(info.getSubtitle());
        infoBO.setAuthor(info.getAuthor());
        infoBO.setOtherAuthors(info.getOtherAuthors());
        infoBO.setPublisher(info.getPublisher());
        infoBO.setPublishDate(info.getPublishDate());
        infoBO.setEdition(info.getEdition());
        infoBO.setCategoryCode(info.getCategoryCode());
        infoBO.setLanguage(info.getLanguage());
        infoBO.setCoverImage(info.getCoverImage());
        infoBO.setSummary(info.getSummary());
        infoBO.setToc(info.getToc());
        infoBO.setPrice(info.getPrice());
        infoBO.setPages(info.getPages());
        infoBO.setDimensions(info.getDimensions());
        infoBO.setBinding(info.getBinding());
        infoBO.setSeries(info.getSeries());
        infoBO.setSource(info.getSource());
        infoBO.setCreatedAt(info.getCreatedAt());
        infoBO.setUpdatedAt(info.getUpdatedAt());
        return infoBO;
    }

    public static InfoDTO infoParamVoToDto(InfoParamVO infoParamVO) {
        if (infoParamVO == null) {
            return null;
        }
        InfoDTO infoDTO = new InfoDTO();
        infoDTO.setId(infoParamVO.getId());
        infoDTO.setIsbn(infoParamVO.getIsbn());
        infoDTO.setTitle(infoParamVO.getTitle());
        infoDTO.setSubtitle(infoParamVO.getSubtitle());
        infoDTO.setAuthor(infoParamVO.getAuthor());
        infoDTO.setOtherAuthors(infoParamVO.getOtherAuthors());
        infoDTO.setPublisher(infoParamVO.getPublisher());
        infoDTO.setPublishDate(infoParamVO.getPublishDate());
        infoDTO.setEdition(infoParamVO.getEdition());
        infoDTO.setCategoryCode(infoParamVO.getCategoryCode());
        infoDTO.setLanguage(infoParamVO.getLanguage());
        infoDTO.setCoverImage(infoParamVO.getCoverImage());
        infoDTO.setSummary(infoParamVO.getSummary());
        infoDTO.setToc(infoParamVO.getToc());
        infoDTO.setPrice(infoParamVO.getPrice());
        infoDTO.setPages(infoParamVO.getPages());
        infoDTO.setDimensions(infoParamVO.getDimensions());
        infoDTO.setBinding(infoParamVO.getBinding());
        infoDTO.setSeries(infoParamVO.getSeries());
        infoDTO.setSource(infoParamVO.getSource());
        infoDTO.setCreatedAt(infoParamVO.getCreatedAt());
        infoDTO.setUpdatedAt(infoParamVO.getUpdatedAt());
        infoDTO.setFilePaths(infoParamVO.getFilePaths());
        return infoDTO;
    }

    public static List<InfoBO> infoListToInfoBOList(List<Info> records) {
         if (ObjectUtils.isEmpty(records)) {
             return new ArrayList<>();
         }
         List<InfoBO> infoBOList = new ArrayList<>();
         for (Info info : records) {
             infoBOList.add(infoDoToBo(info));
         }
         return infoBOList;
    }

    public static InfoVO infoBoToVo(InfoBO infoBO) {
        if (infoBO == null) {
            return null;
        }
        InfoVO infoVO = new InfoVO();
        infoVO.setId(infoBO.getId());
        infoVO.setIsbn(infoBO.getIsbn());
        infoVO.setTitle(infoBO.getTitle());
        infoVO.setSubtitle(infoBO.getSubtitle());
        infoVO.setAuthor(infoBO.getAuthor());
        infoVO.setOtherAuthors(infoBO.getOtherAuthors());
        infoVO.setPublisher(infoBO.getPublisher());
        infoVO.setPublishDate(infoBO.getPublishDate());
        infoVO.setEdition(infoBO.getEdition());
        infoVO.setCategoryCode(infoBO.getCategoryCode());
        infoVO.setLanguage(infoBO.getLanguage());
        infoVO.setCoverImage(infoBO.getCoverImage());
        infoVO.setSummary(infoBO.getSummary());
        infoVO.setToc(infoBO.getToc());
        infoVO.setPrice(infoBO.getPrice());
        infoVO.setPages(infoBO.getPages());
        infoVO.setDimensions(infoBO.getDimensions());
        infoVO.setBinding(infoBO.getBinding());
        infoVO.setSeries(infoBO.getSeries());
        infoVO.setSource(infoBO.getSource());
        infoVO.setCreatedAt(infoBO.getCreatedAt());
        infoVO.setUpdatedAt(infoBO.getUpdatedAt());
        return infoVO;
    }

    public static InfoListDTO infoListParamVoToDTO(InfoListParamVO infoListParamVO) {
        if (infoListParamVO == null) {
            return new InfoListDTO();
        }
        InfoListDTO infoListDTO = new InfoListDTO();
        infoListDTO.setInfoName(infoListParamVO.getInfoName());
        infoListDTO.setCategoryCode(infoListParamVO.getCategoryCode());
        infoListDTO.setPageNo(infoListParamVO.getPageNo());
        infoListDTO.setPageRows(infoListParamVO.getPageRows());
        infoListDTO.setDelFlag(infoListParamVO.getDelFlag());
        infoListDTO.setCreator(infoListParamVO.getCreator());
        infoListDTO.setCreateBeginTime(infoListParamVO.getCreateBeginTime());
        infoListDTO.setCreateEndTime(infoListParamVO.getCreateEndTime());
        infoListDTO.setModifier(infoListParamVO.getModifier());
        infoListDTO.setUpdateBeginTime(infoListParamVO.getUpdateBeginTime());
        infoListDTO.setUpdateEndTime(infoListParamVO.getUpdateEndTime());
        infoListDTO.setRemark(infoListParamVO.getRemark());
        return infoListDTO;
    }
        
    public static InfoListParamVO infoListParamDtoToVo(InfoListDTO infoListDTO) {
        if (infoListDTO == null) {
            return new InfoListParamVO();
        }
        InfoListParamVO infoListParamVO = new InfoListParamVO();
        infoListParamVO.setInfoName(infoListDTO.getInfoName());
        infoListParamVO.setPageNo(infoListDTO.getPageNo());
        infoListParamVO.setPageRows(infoListDTO.getPageRows());
        infoListParamVO.setDelFlag(infoListDTO.getDelFlag());
        infoListParamVO.setCreator(infoListDTO.getCreator());
        infoListParamVO.setCreateBeginTime(infoListDTO.getCreateBeginTime());
        infoListParamVO.setCreateEndTime(infoListDTO.getCreateEndTime());
        infoListParamVO.setModifier(infoListDTO.getModifier());
        infoListParamVO.setUpdateBeginTime(infoListDTO.getUpdateBeginTime());
        infoListParamVO.setUpdateEndTime(infoListDTO.getUpdateEndTime());
        infoListParamVO.setRemark(infoListDTO.getRemark());
        return infoListParamVO;
    }

    private static List<InfoVO> infoBoListToInfoVoList(List<InfoBO> dataList) {
        if (ObjectUtils.isEmpty(dataList)) {
            return new ArrayList<>();
        }
        List<InfoVO> infoVOList = new ArrayList<>();
        for (InfoBO infoBO : dataList) {
             infoVOList.add(infoBoToVo(infoBO));
        }
        return infoVOList;
    }

    public static InfoResultVO infoResultBoToVo(InfoResultBO infoResultBO) {
        if (infoResultBO == null) {
            return new InfoResultVO();
        }
        InfoResultVO infoResultVO = new InfoResultVO();
        infoResultVO.setPageNo(infoResultBO.getPageNo());
        infoResultVO.setPageRows(infoResultBO.getPageRows());
        infoResultVO.setPageCount(infoResultBO.getPageCount());
        infoResultVO.setTotalRows(infoResultBO.getTotalRows());
        infoResultVO.setDataList(infoBoListToInfoVoList(infoResultBO.getDataList()));
        infoResultVO.setParams(infoListParamDtoToVo(infoResultBO.getParams()));
        return infoResultVO;
    }
}