package application.port.output;

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

@Slf4j
@ApplicationScoped
public class RegisterSecurityUseCase implements IRegisterSecurity {

    private final IRegisterSecurityPort registerSecurityPort;

    @Inject
    public RegisterSecurityUseCase(IRegisterSecurityPort registerSecurityPort) {
        this.registerSecurityPort = registerSecurityPort;
    }

    @Override
    public void execute(RegisterSecurityCommand command, String requestId) {
        log.debug(LoggerHelper.buildInfoPrivateRequest(requestId, "Iniciando caso de uso: Registrar traza de seguridad"));
        try {
            registerSecurityPort.writeTrace(command, requestId);
        } catch (GatewayServiceException ex) {
            log.error(LoggerHelper.buildError(requestId, "Fallo la comunicacion con el servicio de register security"));
            throw  ex;
        } finally {
            log.debug(LoggerHelper.buildInfoPrivateResponse(requestId, "Finalizado caso de uso: Registrar traza de seguridad"));
        }
    }
}