package infrastructure.mapper;

import com.banesco.common.infraestructure.helpers.AccountHelper;
import domain.model.BankingProduct;
import domain.model.CustomerAccount;

import java.util.List;

public class BankingProductMapper {

    public static List<BankingProduct> fromCustomerAccountList(List<CustomerAccount> customerAccount, boolean maskAccount) {
        final String USDCurrency = "USD";
        return customerAccount.stream()
                .map(data -> BankingProduct.builder()
                        .productNumber(
                                maskAccount ?
                                        (USDCurrency.equals(data.getMoneda()) ?
                                                AccountHelper.getTotalMaskedAccountId(data.getCuenta())
                                                : AccountHelper.getMaskedAccountId(data.getCuenta())
                                        ) :
                                        data.getCuenta()
                        )
                        .productType(data.getTipoCta())
                        .balance(data.getSaldoDisponible())
                        .currency(data.getMoneda())
                        .build()).toList();
    }
}