package com.banesco.infrastructure.rest;

import com.banesco.common.domain.dto.bian.response.StatusResponse;
import com.banesco.common.domain.model.ApiConfig;
import com.banesco.commons.config.AppConf;
import com.banesco.domain.bian.request.BusUpdateCardStatusRequest;
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 = "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 StatusResponse updateCardStatus(String productAccountId, BusUpdateCardStatusRequest request) {


        return paymentRepository.updateCardStatus(
                this.paymentCardMapper.toBusinessRequest(
                        appConf.getCurrentState(request.getRequestId()),
                        request
                )
        );


    }


}
