package com.banesco.domain.services;

import com.banesco.common.application.exception.BanBackendException;
import com.banesco.common.domain.dto.bian.response.StatusResponse;
import com.banesco.commons.config.StatusCodes;
import com.banesco.domain.bian.request.RecUpdateCardStatusRequest;
import com.banesco.domain.models.CurrentState;
import com.banesco.domain.ports.inbound.UpdateCardStatusUseCase;
import com.banesco.domain.ports.outbound.PaymentCardPort;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@ApplicationScoped
public class UpdateCardStatusService implements UpdateCardStatusUseCase {


    private final PaymentCardPort paymentCardPort;
    private final String RESULT_OK = StatusCodes.SUCCESS_OPERATION.getStatusCode();

    @Inject
    public UpdateCardStatusService(PaymentCardPort paymentCardPort) {
        this.paymentCardPort = paymentCardPort;

    }


    @Override
    public void execute(CurrentState currentState,
                                  RecUpdateCardStatusRequest request) {

        StatusResponse statusResponse = paymentCardPort.updateCardStatus(currentState, request);

        if (!statusResponse.statusCode().equals(RESULT_OK)) {
            throw new BanBackendException(statusResponse.statusCode(), statusResponse.message());
        }

    }


}
