package com.jeeplus.calendar.service.mapstruct;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.calendar.domain.MyCalendar;
import com.jeeplus.calendar.service.dto.MyCalendarDTO;
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 MyCalendarWrapperImpl implements MyCalendarWrapper {

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

        List <MyCalendar> list = new ArrayList <MyCalendar> ( arg0.size ( ) );
        for (MyCalendarDTO myCalendarDTO : arg0) {
            list.add ( toEntity ( myCalendarDTO ) );
        }

        return list;
    }

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

        List <MyCalendarDTO> list = new ArrayList <MyCalendarDTO> ( arg0.size ( ) );
        for (MyCalendar myCalendar : arg0) {
            list.add ( toDTO ( myCalendar ) );
        }

        return list;
    }

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

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

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

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

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

        MyCalendar myCalendar = new MyCalendar ( );

        myCalendar.setUserId ( dtoUserDTOId ( dto ) );
        myCalendar.setId ( dto.getId ( ) );
        myCalendar.setTitle ( dto.getTitle ( ) );
        myCalendar.setStart ( dto.getStart ( ) );
        myCalendar.setEnd ( dto.getEnd ( ) );
        myCalendar.setAllDay ( dto.getAllDay ( ) );
        myCalendar.setColor ( dto.getColor ( ) );

        return myCalendar;
    }

    @Override
    public MyCalendarDTO toDTO(MyCalendar entity) {
        if ( entity == null ) {
            return null;
        }

        MyCalendarDTO myCalendarDTO = new MyCalendarDTO ( );

        myCalendarDTO.setUserDTO ( myCalendarToUserDTO ( entity ) );
        myCalendarDTO.setId ( entity.getId ( ) );
        myCalendarDTO.setTitle ( entity.getTitle ( ) );
        myCalendarDTO.setStart ( entity.getStart ( ) );
        myCalendarDTO.setEnd ( entity.getEnd ( ) );
        myCalendarDTO.setAllDay ( entity.getAllDay ( ) );
        myCalendarDTO.setColor ( entity.getColor ( ) );

        return myCalendarDTO;
    }

    private String dtoUserDTOId(MyCalendarDTO myCalendarDTO) {
        if ( myCalendarDTO == null ) {
            return null;
        }
        UserDTO userDTO = myCalendarDTO.getUserDTO ( );
        if ( userDTO == null ) {
            return null;
        }
        String id = userDTO.getId ( );
        if ( id == null ) {
            return null;
        }
        return id;
    }

    protected UserDTO myCalendarToUserDTO(MyCalendar myCalendar) {
        if ( myCalendar == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO ( );

        userDTO.setId ( myCalendar.getUserId ( ) );

        return userDTO;
    }
}
