package com.jeeplus.form.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.form.domain.Form;
import com.jeeplus.form.service.dto.FormDTO;
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 FormWrapperImpl implements FormWrapper {

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

        List <Form> list = new ArrayList <Form> ( arg0.size ( ) );
        for (FormDTO formDTO : arg0) {
            list.add ( toEntity ( formDTO ) );
        }

        return list;
    }

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

        List <FormDTO> list = new ArrayList <FormDTO> ( arg0.size ( ) );
        for (Form form : arg0) {
            list.add ( toDTO ( form ) );
        }

        return list;
    }

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

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

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

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

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

        Form form = new Form ( );

        form.setCreateById ( dtoCreateById ( dto ) );
        form.setUpdateById ( dtoUpdateById ( dto ) );
        form.setDataSourceId ( dtoDataSourceId ( dto ) );
        form.setId ( dto.getId ( ) );
        form.setCreateTime ( dto.getCreateTime ( ) );
        form.setUpdateTime ( dto.getUpdateTime ( ) );
        form.setDelFlag ( dto.getDelFlag ( ) );
        form.setCode ( dto.getCode ( ) );
        form.setAutoCreate ( dto.getAutoCreate ( ) );
        form.setName ( dto.getName ( ) );
        form.setTableName ( dto.getTableName ( ) );
        form.setSource ( dto.getSource ( ) );
        form.setVersion ( dto.getVersion ( ) );
        form.setRemarks ( dto.getRemarks ( ) );

        return form;
    }

    @Override
    public FormDTO toDTO(Form entity) {
        if ( entity == null ) {
            return null;
        }

        FormDTO formDTO = new FormDTO ( );

        formDTO.setCreateBy ( formToUserDTO ( entity ) );
        formDTO.setUpdateBy ( formToUserDTO1 ( entity ) );
        formDTO.setDataSource ( formToDataSource ( entity ) );
        formDTO.setId ( entity.getId ( ) );
        formDTO.setCreateTime ( entity.getCreateTime ( ) );
        formDTO.setUpdateTime ( entity.getUpdateTime ( ) );
        formDTO.setDelFlag ( entity.getDelFlag ( ) );
        formDTO.setCode ( entity.getCode ( ) );
        formDTO.setAutoCreate ( entity.getAutoCreate ( ) );
        formDTO.setName ( entity.getName ( ) );
        formDTO.setTableName ( entity.getTableName ( ) );
        formDTO.setSource ( entity.getSource ( ) );
        formDTO.setVersion ( entity.getVersion ( ) );
        formDTO.setRemarks ( entity.getRemarks ( ) );

        return formDTO;
    }

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

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

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

    protected UserDTO formToUserDTO(Form form) {
        if ( form == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( form.getCreateById ( ) );

        return userDTO;
    }

    protected UserDTO formToUserDTO1(Form form) {
        if ( form == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( form.getUpdateById ( ) );

        return userDTO;
    }

    protected DataSource formToDataSource(Form form) {
        if ( form == null ) {
            return null;
        }

        DataSource dataSource = new DataSource ( );

        dataSource.setId ( form.getDataSourceId ( ) );

        return dataSource;
    }
}
