AccountJpaMapperImpl.java

package com.github.jenkaby.bikerental.finance.infrastructure.persistence.mapper;

import com.github.jenkaby.bikerental.finance.domain.model.CustomerAccount;
import com.github.jenkaby.bikerental.finance.domain.model.SubLedger;
import com.github.jenkaby.bikerental.finance.domain.model.SystemAccount;
import com.github.jenkaby.bikerental.finance.infrastructure.persistence.entity.AccountJpaEntity;
import com.github.jenkaby.bikerental.finance.infrastructure.persistence.entity.SubLedgerJpaEntity;
import com.github.jenkaby.bikerental.shared.mapper.CustomerRefMapper;
import com.github.jenkaby.bikerental.shared.mapper.MoneyMapper;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    comments = "version: 1.6.3, compiler: IncrementalProcessingEnvironment from gradle-language-java-9.4.1.jar, environment: Java 21.0.10 (Amazon.com Inc.)"
)
@Component
public class AccountJpaMapperImpl implements AccountJpaMapper {

    private final MoneyMapper moneyMapper;
    private final CustomerRefMapper customerRefMapper;

    @Autowired
    public AccountJpaMapperImpl(MoneyMapper moneyMapper, CustomerRefMapper customerRefMapper) {

        this.moneyMapper = moneyMapper;
        this.customerRefMapper = customerRefMapper;
    }

    @Override
    public CustomerAccount toCustomerAccountDomain(AccountJpaEntity entity) {
        if ( entity == null ) {
            return null;
        }

        CustomerAccount.CustomerAccountBuilder<?, ?> customerAccount = CustomerAccount.builder();

        customerAccount.customerRef( customerRefMapper.fromUUID( entity.getCustomerId() ) );
        customerAccount.id( entity.getId() );
        customerAccount.subLedgers( subLedgerJpaEntityListToSubLedgerList( entity.getSubLedgers() ) );

        return customerAccount.build();
    }

    @Override
    public SystemAccount toSystemAccountDomain(AccountJpaEntity entity) {
        if ( entity == null ) {
            return null;
        }

        SystemAccount.SystemAccountBuilder<?, ?> systemAccount = SystemAccount.builder();

        systemAccount.id( entity.getId() );
        systemAccount.subLedgers( subLedgerJpaEntityListToSubLedgerList( entity.getSubLedgers() ) );

        return systemAccount.build();
    }

    @Override
    public AccountJpaEntity toEntity(CustomerAccount domain) {
        if ( domain == null ) {
            return null;
        }

        AccountJpaEntity.AccountJpaEntityBuilder accountJpaEntity = AccountJpaEntity.builder();

        accountJpaEntity.customerId( customerRefMapper.toUUID( domain.getCustomerRef() ) );
        accountJpaEntity.id( domain.getId() );
        accountJpaEntity.accountType( domain.getAccountType() );
        accountJpaEntity.subLedgers( subLedgerListToSubLedgerJpaEntityList( domain.getSubLedgers() ) );

        AccountJpaEntity accountJpaEntityResult = accountJpaEntity.build();

        setSubLedgerRelationships( accountJpaEntityResult );

        return accountJpaEntityResult;
    }

    @Override
    public AccountJpaEntity toEntity(SystemAccount domain) {
        if ( domain == null ) {
            return null;
        }

        AccountJpaEntity.AccountJpaEntityBuilder accountJpaEntity = AccountJpaEntity.builder();

        accountJpaEntity.id( domain.getId() );
        accountJpaEntity.accountType( domain.getAccountType() );
        accountJpaEntity.subLedgers( subLedgerListToSubLedgerJpaEntityList( domain.getSubLedgers() ) );

        AccountJpaEntity accountJpaEntityResult = accountJpaEntity.build();

        setSubLedgerRelationships( accountJpaEntityResult );

        return accountJpaEntityResult;
    }

    @Override
    public SubLedger toDomain(SubLedgerJpaEntity entity) {
        if ( entity == null ) {
            return null;
        }

        SubLedger.SubLedgerBuilder subLedger = SubLedger.builder();

        subLedger.id( entity.getId() );
        subLedger.ledgerType( entity.getLedgerType() );
        subLedger.balance( moneyMapper.toMoney( entity.getBalance() ) );
        subLedger.version( entity.getVersion() );
        subLedger.updatedAt( entity.getUpdatedAt() );

        return subLedger.build();
    }

    @Override
    public SubLedgerJpaEntity toEntity(SubLedger domain) {
        if ( domain == null ) {
            return null;
        }

        SubLedgerJpaEntity.SubLedgerJpaEntityBuilder subLedgerJpaEntity = SubLedgerJpaEntity.builder();

        subLedgerJpaEntity.id( domain.getId() );
        subLedgerJpaEntity.ledgerType( domain.getLedgerType() );
        subLedgerJpaEntity.balance( moneyMapper.toBigDecimal( domain.getBalance() ) );
        subLedgerJpaEntity.version( domain.getVersion() );

        return subLedgerJpaEntity.build();
    }

    protected List<SubLedger> subLedgerJpaEntityListToSubLedgerList(List<SubLedgerJpaEntity> list) {
        if ( list == null ) {
            return null;
        }

        List<SubLedger> list1 = new ArrayList<SubLedger>( list.size() );
        for ( SubLedgerJpaEntity subLedgerJpaEntity : list ) {
            list1.add( toDomain( subLedgerJpaEntity ) );
        }

        return list1;
    }

    protected List<SubLedgerJpaEntity> subLedgerListToSubLedgerJpaEntityList(List<SubLedger> list) {
        if ( list == null ) {
            return null;
        }

        List<SubLedgerJpaEntity> list1 = new ArrayList<SubLedgerJpaEntity>( list.size() );
        for ( SubLedger subLedger : list ) {
            list1.add( toEntity( subLedger ) );
        }

        return list1;
    }
}