package cz.moneta.test.dsl.udebs;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.udebs.UdebsEndpoint;
import cz.moneta.test.harness.exception.HarnessException;

import java.util.Optional;

public class TransactionStatusBuilder {

    private static final String SET_STATUS_TO_51 =
            "BEGIN " +
                    "    geutils.API_GECON.SetStatusTo51( " +
                    "        inList    => '%s', " +
                    "        inGecUser => '%s' ); " +
                    "END;";

    private final StoreAccessor harness;

    public TransactionStatusBuilder(StoreAccessor harness) {
        this.harness = harness;
    }

    public void setStatusTo51(String packageIdList, String userId) {
        Optional.of(harness.getEndpoint(UdebsEndpoint.class))
                .map(e -> e.executeSql(String.format(SET_STATUS_TO_51, packageIdList, userId)))
                .orElseThrow(() -> new HarnessException("Error: I couldn't set transaction status to 51"));
    }
}