package com.jeeplus.mail.service.mapstruct;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.mail.domain.Mail;
import com.jeeplus.mail.service.dto.MailDTO;
import com.jeeplus.sys.service.dto.UserDTO;
import org.springframework.stereotype.Component;

import javax.annotation.Generated;
import java.util.ArrayList;
import java.util.List;

@Generated(
        value = "org.mapstruct.ap.MappingProcessor",
        date = "2022-08-18T16:46:54+0800",
        comments = "version: 1.4.1.Final, compiler: javac, environment: Java 1.8.0_221 (Oracle Corporation)"
)
@Component
public class MailWrapperImpl implements MailWrapper {

    @Override
    public List <Mail> toEntity(List <MailDTO> arg0) {
        if ( arg0 == null ) {
            return null;
        }

        List <Mail> list = new ArrayList <Mail> ( arg0.size ( ) );
        for (MailDTO mailDTO : arg0) {
            list.add ( toEntity ( mailDTO ) );
        }

        return list;
    }

    @Override
    public List <MailDTO> toDTO(List <Mail> arg0) {
        if ( arg0 == null ) {
            return null;
        }

        List <MailDTO> list = new ArrayList <MailDTO> ( arg0.size ( ) );
        for (Mail mail : arg0) {
            list.add ( toDTO ( mail ) );
        }

        return list;
    }

    @Override
    public Page <Mail> toEntity(Page <MailDTO> arg0) {
        if ( arg0 == null ) {
            return null;
        }

        Page <Mail> page = new Page <Mail> ( );

        page.setPages ( arg0.getPages ( ) );
        page.setRecords ( toEntity ( arg0.getRecords ( ) ) );
        page.setTotal ( arg0.getTotal ( ) );
        page.setSize ( arg0.getSize ( ) );
        page.setCurrent ( arg0.getCurrent ( ) );
        page.setSearchCount ( arg0.isSearchCount ( ) );
        page.setOptimizeCountSql ( arg0.isOptimizeCountSql ( ) );
        page.setHitCount ( arg0.isHitCount ( ) );
        List <OrderItem> list1 = arg0.getOrders ( );
        if ( list1 != null ) {
            page.setOrders ( new ArrayList <OrderItem> ( list1 ) );
        }
        page.setCountId ( arg0.getCountId ( ) );
        page.setMaxLimit ( arg0.getMaxLimit ( ) );

        return page;
    }

    @Override
    public Page <MailDTO> toDTO(Page <Mail> arg0) {
        if ( arg0 == null ) {
            return null;
        }

        Page <MailDTO> page = new Page <MailDTO> ( );

        page.setPages ( arg0.getPages ( ) );
        page.setRecords ( toDTO ( arg0.getRecords ( ) ) );
        page.setTotal ( arg0.getTotal ( ) );
        page.setSize ( arg0.getSize ( ) );
        page.setCurrent ( arg0.getCurrent ( ) );
        page.setSearchCount ( arg0.isSearchCount ( ) );
        page.setOptimizeCountSql ( arg0.isOptimizeCountSql ( ) );
        page.setHitCount ( arg0.isHitCount ( ) );
        List <OrderItem> list1 = arg0.getOrders ( );
        if ( list1 != null ) {
            page.setOrders ( new ArrayList <OrderItem> ( list1 ) );
        }
        page.setCountId ( arg0.getCountId ( ) );
        page.setMaxLimit ( arg0.getMaxLimit ( ) );

        return page;
    }

    @Override
    public Mail toEntity(MailDTO dto) {
        if ( dto == null ) {
            return null;
        }

        Mail mail = new Mail ( );

        mail.setCreateById ( dtoCreateById ( dto ) );
        mail.setUpdateById ( dtoUpdateById ( dto ) );
        mail.setId ( dto.getId ( ) );
        mail.setCreateTime ( dto.getCreateTime ( ) );
        mail.setUpdateTime ( dto.getUpdateTime ( ) );
        mail.setDelFlag ( dto.getDelFlag ( ) );
        mail.setTitle ( dto.getTitle ( ) );
        mail.setOverview ( dto.getOverview ( ) );
        mail.setContent ( dto.getContent ( ) );

        return mail;
    }

    @Override
    public MailDTO toDTO(Mail entity) {
        if ( entity == null ) {
            return null;
        }

        MailDTO mailDTO = new MailDTO ( );

        mailDTO.setCreateBy ( mailToUserDTO ( entity ) );
        mailDTO.setUpdateBy ( mailToUserDTO1 ( entity ) );
        mailDTO.setId ( entity.getId ( ) );
        mailDTO.setCreateTime ( entity.getCreateTime ( ) );
        mailDTO.setUpdateTime ( entity.getUpdateTime ( ) );
        mailDTO.setDelFlag ( entity.getDelFlag ( ) );
        mailDTO.setTitle ( entity.getTitle ( ) );
        mailDTO.setOverview ( entity.getOverview ( ) );
        mailDTO.setContent ( entity.getContent ( ) );

        return mailDTO;
    }

    private String dtoCreateById(MailDTO mailDTO) {
        if ( mailDTO == null ) {
            return null;
        }
        UserDTO createBy = mailDTO.getCreateBy ( );
        if ( createBy == null ) {
            return null;
        }
        String id = createBy.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    private String dtoUpdateById(MailDTO mailDTO) {
        if ( mailDTO == null ) {
            return null;
        }
        UserDTO updateBy = mailDTO.getUpdateBy ( );
        if ( updateBy == null ) {
            return null;
        }
        String id = updateBy.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    protected UserDTO mailToUserDTO(Mail mail) {
        if ( mail == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( mail.getCreateById ( ) );

        return userDTO;
    }

    protected UserDTO mailToUserDTO1(Mail mail) {
        if ( mail == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( mail.getUpdateById ( ) );

        return userDTO;
    }
}
