package com.example.backend.core.configuration;

import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.backend.core.model.BaseEntity;
import com.example.backend.orders.api.OrderDto;
import com.example.backend.orders.model.OrderEntity;

@Configuration
public class MapperConfiguration {
    @Bean
    ModelMapper modelMapper() {
        ModelMapper modelMapper = new ModelMapper();
        modelMapper.typeMap(OrderEntity.class, OrderDto.class).addMappings(mapper -> mapper.skip(OrderDto::setBooks));
        modelMapper.addMappings(new PropertyMap<Object, BaseEntity>() {
            @Override
            protected void configure() {
                skip(destination.getId());
            }
        });
        return modelMapper;
    }
}
