package com.jeeplus.sys.service.mapstruct;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.sys.domain.Post;
import com.jeeplus.sys.service.dto.PostDTO;
import com.jeeplus.sys.service.dto.TenantDTO;
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 PostWrapperImpl implements PostWrapper {

    @Override
    public Post toEntity(PostDTO arg0) {
        if ( arg0 == null ) {
            return null;
        }

        Post post = new Post ( );

        post.setTenantId ( arg0TenantDTOId ( arg0 ) );
        post.setCreateById ( arg0CreateById ( arg0 ) );
        post.setUpdateById ( arg0UpdateById ( arg0 ) );
        post.setId ( arg0.getId ( ) );
        post.setCreateTime ( arg0.getCreateTime ( ) );
        post.setUpdateTime ( arg0.getUpdateTime ( ) );
        post.setDelFlag ( arg0.getDelFlag ( ) );
        post.setName ( arg0.getName ( ) );
        post.setCode ( arg0.getCode ( ) );
        post.setType ( arg0.getType ( ) );
        post.setStatus ( arg0.getStatus ( ) );
        post.setSort ( arg0.getSort ( ) );
        post.setRemarks ( arg0.getRemarks ( ) );

        return post;
    }

    @Override
    public PostDTO toDTO(Post arg0) {
        if ( arg0 == null ) {
            return null;
        }

        PostDTO postDTO = new PostDTO ( );

        postDTO.setTenantDTO ( postToTenantDTO ( arg0 ) );
        postDTO.setCreateBy ( postToUserDTO ( arg0 ) );
        postDTO.setUpdateBy ( postToUserDTO1 ( arg0 ) );
        postDTO.setId ( arg0.getId ( ) );
        postDTO.setCreateTime ( arg0.getCreateTime ( ) );
        postDTO.setUpdateTime ( arg0.getUpdateTime ( ) );
        postDTO.setDelFlag ( arg0.getDelFlag ( ) );
        postDTO.setName ( arg0.getName ( ) );
        postDTO.setCode ( arg0.getCode ( ) );
        postDTO.setType ( arg0.getType ( ) );
        postDTO.setStatus ( arg0.getStatus ( ) );
        postDTO.setRemarks ( arg0.getRemarks ( ) );
        postDTO.setSort ( arg0.getSort ( ) );

        return postDTO;
    }

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

        List <Post> list = new ArrayList <Post> ( arg0.size ( ) );
        for (PostDTO postDTO : arg0) {
            list.add ( toEntity ( postDTO ) );
        }

        return list;
    }

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

        List <PostDTO> list = new ArrayList <PostDTO> ( arg0.size ( ) );
        for (Post post : arg0) {
            list.add ( toDTO ( post ) );
        }

        return list;
    }

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

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

        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 <PostDTO> toDTO(Page <Post> arg0) {
        if ( arg0 == null ) {
            return null;
        }

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

        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;
    }

    private String arg0TenantDTOId(PostDTO postDTO) {
        if ( postDTO == null ) {
            return null;
        }
        TenantDTO tenantDTO = postDTO.getTenantDTO ( );
        if ( tenantDTO == null ) {
            return null;
        }
        String id = tenantDTO.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    private String arg0CreateById(PostDTO postDTO) {
        if ( postDTO == null ) {
            return null;
        }
        UserDTO createBy = postDTO.getCreateBy ( );
        if ( createBy == null ) {
            return null;
        }
        String id = createBy.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    private String arg0UpdateById(PostDTO postDTO) {
        if ( postDTO == null ) {
            return null;
        }
        UserDTO updateBy = postDTO.getUpdateBy ( );
        if ( updateBy == null ) {
            return null;
        }
        String id = updateBy.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    protected TenantDTO postToTenantDTO(Post post) {
        if ( post == null ) {
            return null;
        }

        TenantDTO tenantDTO = new TenantDTO ( );

        tenantDTO.setId ( post.getTenantId ( ) );

        return tenantDTO;
    }

    protected UserDTO postToUserDTO(Post post) {
        if ( post == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( post.getCreateById ( ) );

        return userDTO;
    }

    protected UserDTO postToUserDTO1(Post post) {
        if ( post == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( post.getUpdateById ( ) );

        return userDTO;
    }
}
