package application.usecase;

import application.exception.GatewayServiceException;
import application.port.input.IEncodeValue;
import application.port.input.command.EncodeValueCommand;
import com.banesco.common.infraestructure.helpers.LoggerHelper;
import domain.repository.IEncodeValuePort;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ApplicationScoped
public class EncodeValueUseCase implements IEncodeValue {

    private final IEncodeValuePort encodeValuePort;

    @Inject
    public EncodeValueUseCase(IEncodeValuePort encodeValuePort) {
        this.encodeValuePort = encodeValuePort;
    }

    @Override
    public String execute(EncodeValueCommand command, String requestId) {
        log.debug(LoggerHelper.buildInfoPrivateRequest(requestId, "Iniciando caso de uso: Encode Value"));
        try {
            return encodeValuePort.execute(command, requestId);
        } catch (GatewayServiceException ex) {
            log.error(LoggerHelper.buildError(requestId, "Fallo la comunicacion con el servicio de Encode Value: " + ex.getMessage()));
            throw ex;
        } finally {
            log.debug(LoggerHelper.buildInfoPrivateRequest(requestId, "Finalizado caso de uso: Encode Value"));
        }
    }

}