package com.banesco.infrastructure.rest;

import com.banesco.common.domain.dto.bian.response.BianStatusResponse;
import com.banesco.common.domain.model.ApiConfig;
import com.banesco.commons.config.AppConf;
import com.banesco.domain.bian.request.RecUpdateCardStatusRequest;
import com.banesco.domain.models.CurrentState;
import com.banesco.domain.ports.outbound.PaymentCardPort;
import com.banesco.infrastructure.rest.mappers.PaymentCardMapper;
import com.banesco.infrastructure.rest.repositories.PaymentCardRepository;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;


@ApplicationScoped
@Slf4j
public class PaymentCardAdapter implements PaymentCardPort {


    private final PaymentCardRepository paymentRepository;
    private final PaymentCardMapper paymentCardMapper;

    private final String OPERATION_NAME = "bus-update-card-status";
    AppConf appConf;

    @Inject
    public PaymentCardAdapter(AppConf appConf,
                              PaymentCardMapper paymentCardMapper) {

        this.appConf = appConf;
        this.paymentCardMapper = paymentCardMapper;
        ApiConfig apiConfig = appConf.loadApiConfig("api.rest-client." + OPERATION_NAME);
        paymentRepository = new PaymentCardRepository(apiConfig);

    }


    public BianStatusResponse updateCardStatus(CurrentState currentState, RecUpdateCardStatusRequest request) {


        return paymentRepository.updateCardStatus(
                this.paymentCardMapper.toBusinessRequest(
                        currentState,
                        request
                )
        );

        /*

        BianStatusResponse statusResponse;

        if (request.getCustomerReference().getCustomerIdType().equals("J")) {
            statusResponse = new BianStatusResponse(
                    "ok",
                    StatusCodes.SUCCESS_OPERATION.getStatusCode(),

                    "Operacion realizada con exito",
                    currentState.requestId()
            );
        } else {
            statusResponse = new BianStatusResponse(
                    "error",
                    StatusCodes.FAILED_DEPENDENCY.getStatusCode(),
                    "Error al procesar la solicitud",
                    currentState.requestId()
            );
        }


        return statusResponse;
*/
    }


}
