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 ClientPaymentsLimitsBuilder {

    private final StoreAccessor harness;
    private String LIMITS_SQL = "SELECT B.LIMITAMOUNT LIMIT FROM \n" +
            "CLIENTRIGHTPROFILES C, \n" +
            "CLIENTPROFILEPAYMENTLIMITS B, \n" +
            "PAYMENTLIMITCHANNEL A, \n" +
            "CLIENTCHANNELPROFILES D \n" +
            "WHERE C.RIGHTPROFILEID = B.RIGHTPROFILEID \n" +
            "AND B.PAYMENTLIMITID = A.PAYMENTLIMITID \n" +
            "AND D.CLIENTID = C.CLIENTID \n" +
            "AND C.CLIENTID IN (SELECT CLI.CLIENTID  FROM  CLIENTHOSTALLOCATION CLI \n" +
            "WHERE SUBSTR(CLI.HOSTCLIENTID,4,10) = '%s') \n" +
            "AND D.CHANNELID = 23 \n" +
            "AND A.CHANNELID = 23";

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

    public Result<Record> getLimitsAmount(String cif) {
        return harness.getEndpoint(UdebsEndpoint.class).executeSql(String.format(LIMITS_SQL, cif));
    }

}
