# What MapStruct 1.6.3 generated, read from target/generated-sources (header and imports trimmed)


--- AddressMapperImpl ---
@Component
public class AddressMapperImpl implements AddressMapper {

    @Override
    public AddressDto toDto(Address address) {
        if ( address == null ) {
            return null;
        }

        String zip = null;
        String country = null;
        String street = null;
        String city = null;

        zip = address.getPostalCode();
        if ( address.getCountry() != null ) {
            country = address.getCountry();
        }
        else {
            country = "IN";
        }
        street = address.getStreet();
        city = address.getCity();

        AddressDto addressDto = new AddressDto( street, city, zip, country );

        return addressDto;
    }

    @Override
    public Address toEntity(AddressDto dto) {
        if ( dto == null ) {
            return null;
        }

        Address address = new Address();

        address.setPostalCode( dto.zip() );
        address.setCountry( dto.country() );
        address.setStreet( dto.street() );
        address.setCity( dto.city() );

        return address;
    }

    @Override
    public void update(AddressDto dto, Address address) {
        if ( dto == null ) {
            return;
        }

        if ( dto.zip() != null ) {
            address.setPostalCode( dto.zip() );
        }
        if ( dto.street() != null ) {
            address.setStreet( dto.street() );
        }
        if ( dto.city() != null ) {
            address.setCity( dto.city() );
        }
        if ( dto.country() != null ) {
            address.setCountry( dto.country() );
        }
    }
}

--- CustomerMapperImpl: constructor injection, then toDto ---
@Component
public class CustomerMapperImpl implements CustomerMapper {

    private final AddressMapper addressMapper;
    private final OrderMapper orderMapper;

    @Autowired
    public CustomerMapperImpl(AddressMapper addressMapper, OrderMapper orderMapper) {

        this.addressMapper = addressMapper;
        this.orderMapper = orderMapper;
    }

    public CustomerDto toDto(Customer customer, Clock clock) {
        if ( customer == null ) {
            return null;
        }

        int age = 0;
        String nickname = null;
        Long id = null;
        String email = null;
        LocalDate birthDate = null;
        AddressDto address = null;
        Set<String> roles = null;
        Map<String, String> attributes = null;
        List<OrderDto> orders = null;

        age = ageInYears( customer.getBirthDate(), clock );
        if ( customer.getNickname() != null ) {
            nickname = customer.getNickname();
        }
        else {
            nickname = "anonymous";
        }
        id = customer.getId();
        email = customer.getEmail();
        birthDate = customer.getBirthDate();
        address = addressMapper.toDto( customer.getAddress() );
        Set<String> set = customer.getRoles();
        if ( set != null ) {
            roles = new LinkedHashSet<String>( set );
        }
        Map<String, String> map = customer.getAttributes();
        if ( map != null ) {
            attributes = new LinkedHashMap<String, String>( map );
        }
        orders = orderMapper.toDtos( customer.getOrders() );

        String fullName = customer.getFirstName() + " " + customer.getLastName();
        String origin = "api";

        CustomerDto customerDto = new CustomerDto( id, fullName, email, birthDate, age, nickname, address, roles, attributes, orders, origin );

        return customerDto;
    }
