package infrastructure.mapper;

import application.port.input.command.CustomerAccountCommand;
import domain.model.CustomerAccount;
import infrastructure.client.accounts.dto.request.CustomerAccountRequest;
import infrastructure.client.accounts.dto.respone.CustomerAccountResponse;

import java.util.Collections;
import java.util.List;

public final class CustomerAccountMapper {

    public static List<CustomerAccount> toEntityList(CustomerAccountResponse response) {
        if (response == null || response.getData() == null) {
            return Collections.emptyList();
        }

        return response.getData().stream()
                .map(data -> CustomerAccount.builder()
                        .banco(data.getBanco())
                        .cuenta(data.getCuenta())
                        .producto(data.getProducto())
                        .descProd(data.getDescProd())
                        .claseCta(data.getClaseCta())
                        .tipoCta(data.getTipoCta())
                        .moneda(data.getMoneda())
                        .saldoDisponible(data.getSaldoDisponible())
                        .estatus(data.getEstatus())
                        .statusMe(data.getStatusMe())
                        .titular(data.getTitular())
                        .maximumPerDay(data.getMaximumPerDay())
                        .maximumPerTransaction(data.getMaximumPerTransaction())
                        .maximumPerMonth(data.getMaximumPerMonth())
                        .maximumMonthlyFee(data.getMaximumMonthlyFee())
                        .minimumPerTransaction(data.getMinimumPerTransaction())
                        .operator(data.getOperator())
                        .phone(data.getPhone())
                        .channel(data.getChannel())
                        .service(data.getService())
                        .affiliationStatus(data.getAffiliationStatus())
                        .build()).toList();
    }

    public static CustomerAccountRequest toRequestDto(CustomerAccountCommand command) {
        return CustomerAccountRequest.builder()
                .rif(command.getRif())
                .bankCode(command.getBankCode())
                .currencyCode(command.getCurrencyCode())
                .status(command.getStatus())
                .statusMe(command.getStatusMe())
                .productCv(command.getProductCv())
                .product(command.getProduct())
                .channel(command.getChannel())
                .service(command.getService())
                .operator(command.getOperator())
                .phone(command.getPhone())
                .affiliationStatus(command.getAffiliationStatus())
                .counterpartyAccount(command.getCounterpartyAccount())
                .holder(command.getHolder())
                .build();
    }

}