package cz.moneta.test.dsl.dmbsib;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.dmbsib.DmbsIbEndpoint;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Wait;
import cz.moneta.test.harness.support.web.WebFlow;

import static cz.moneta.test.dsl.dmbsib.ThirdPartyApplicationPageWithStatusCode.BODY_TAG;

@Wait(value = BODY_TAG)
public interface ThirdPartyApplicationPageWithStatusCode extends WebFlow<DmbsIbWebTransitions>, StoreAccessor {

    String BODY_TAG = "//body[contains(.,'gemwebdevx')]";
    String STATUS_CODE_STORE = "STATUS_CODE";

    @CustomAction
    default ThirdPartyApplicationPageWithStatusCode getAuthTokenAndStoreIt() {
        DmbsIbEndpoint endpoint = getEndpoint(DmbsIbEndpoint.class);
        String token = endpoint.getCurrentUrl().split("response_code=")[1];
        log("Status code is: {}", token);
        store(STATUS_CODE_STORE, token);
        return null;
    }
}
