package com.jeeplus.database.datamodel.service.mapstruct;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.database.datalink.domain.DataSource;
import com.jeeplus.database.datamodel.domain.DataSet;
import com.jeeplus.database.datamodel.service.dto.DataSetDTO;
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 DataSetWrapperImpl implements DataSetWrapper {

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

        List <DataSet> list = new ArrayList <DataSet> ( arg0.size ( ) );
        for (DataSetDTO dataSetDTO : arg0) {
            list.add ( toEntity ( dataSetDTO ) );
        }

        return list;
    }

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

        List <DataSetDTO> list = new ArrayList <DataSetDTO> ( arg0.size ( ) );
        for (DataSet dataSet : arg0) {
            list.add ( toDTO ( dataSet ) );
        }

        return list;
    }

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

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

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

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

        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 DataSet toEntity(DataSetDTO dto) {
        if ( dto == null ) {
            return null;
        }

        DataSet dataSet = new DataSet ( );

        dataSet.setTenantId ( dtoTenantDTOId ( dto ) );
        dataSet.setDataSourceId ( dtoDataSourceId ( dto ) );
        dataSet.setCreateById ( dtoCreateById ( dto ) );
        dataSet.setUpdateById ( dtoUpdateById ( dto ) );
        dataSet.setId ( dto.getId ( ) );
        dataSet.setCreateTime ( dto.getCreateTime ( ) );
        dataSet.setUpdateTime ( dto.getUpdateTime ( ) );
        dataSet.setDelFlag ( dto.getDelFlag ( ) );
        dataSet.setName ( dto.getName ( ) );
        dataSet.setSqlCmd ( dto.getSqlCmd ( ) );

        return dataSet;
    }

    @Override
    public DataSetDTO toDTO(DataSet entity) {
        if ( entity == null ) {
            return null;
        }

        DataSetDTO dataSetDTO = new DataSetDTO ( );

        dataSetDTO.setTenantDTO ( dataSetToTenantDTO ( entity ) );
        dataSetDTO.setDataSource ( dataSetToDataSource ( entity ) );
        dataSetDTO.setCreateBy ( dataSetToUserDTO ( entity ) );
        dataSetDTO.setUpdateBy ( dataSetToUserDTO1 ( entity ) );
        dataSetDTO.setId ( entity.getId ( ) );
        dataSetDTO.setCreateTime ( entity.getCreateTime ( ) );
        dataSetDTO.setUpdateTime ( entity.getUpdateTime ( ) );
        dataSetDTO.setDelFlag ( entity.getDelFlag ( ) );
        dataSetDTO.setName ( entity.getName ( ) );
        dataSetDTO.setSqlCmd ( entity.getSqlCmd ( ) );

        return dataSetDTO;
    }

    private String dtoTenantDTOId(DataSetDTO dataSetDTO) {
        if ( dataSetDTO == null ) {
            return null;
        }
        TenantDTO tenantDTO = dataSetDTO.getTenantDTO ( );
        if ( tenantDTO == null ) {
            return null;
        }
        String id = tenantDTO.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    private String dtoDataSourceId(DataSetDTO dataSetDTO) {
        if ( dataSetDTO == null ) {
            return null;
        }
        DataSource dataSource = dataSetDTO.getDataSource ( );
        if ( dataSource == null ) {
            return null;
        }
        String id = dataSource.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

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

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

    protected TenantDTO dataSetToTenantDTO(DataSet dataSet) {
        if ( dataSet == null ) {
            return null;
        }

        TenantDTO tenantDTO = new TenantDTO ( );

        tenantDTO.setId ( dataSet.getTenantId ( ) );

        return tenantDTO;
    }

    protected DataSource dataSetToDataSource(DataSet dataSet) {
        if ( dataSet == null ) {
            return null;
        }

        DataSource dataSource = new DataSource ( );

        dataSource.setId ( dataSet.getDataSourceId ( ) );

        return dataSource;
    }

    protected UserDTO dataSetToUserDTO(DataSet dataSet) {
        if ( dataSet == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( dataSet.getCreateById ( ) );

        return userDTO;
    }

    protected UserDTO dataSetToUserDTO1(DataSet dataSet) {
        if ( dataSet == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( dataSet.getUpdateById ( ) );

        return userDTO;
    }
}
