package cz.moneta.test.dsl.udebs;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.udebs.UdebsEndpoint;
import org.jooq.Record;
import org.jooq.Result;

public class ThirdPartyBuilder {

    private final StoreAccessor harness;

    private String THIRD_PARTY_RIGHTS = "SELECT \n" +
            "TPR.THIRD_PARTY_CODE THIRD_PARTY_CODE,\n" +
            "TPR.ACTIVE_FROM ACTIVE_FROM,\n" +
            "TPR.ACTIVE_TO ACTIVE_TO,\n" +
            "SUBSTR(CLI.HOSTCLIENTID,4,10)CIF \n" +
            "FROM UDEBSGE.THIRD_PARTY_RIGHTS TPR, CLIENTHOSTALLOCATION CLI\n" +
            "WHERE TPR.CLIENTID = CLI.CLIENTID\n" +
            "AND TPR.ACCOUNTID = '%s'" +
            "ORDER BY TPR.RELATIONID DESC";

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

    public Result<Record> getThirdPartyRights(String accountNumber) {
        return harness.getEndpoint(UdebsEndpoint.class).executeSql(String.format(THIRD_PARTY_RIGHTS, accountNumber));
    }
}
