package cz.moneta.test.dsl.util.task.wso2.depersonalization;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.wso2.objects.traininggov.DoDepersCustTestRequest;

/**
 * Depersonalization client for reuse in automated tests.
 * <a href="https://confluence.moneta.cz/x/HpKpVw">API Documentation</a>
 */
public class DepersonalizationTasks {

    private final Harness harness;

    public DepersonalizationTasks(Harness harness) {
        this.harness = harness;
    }

    public void depersonalizeClientFOP(String ico, String cif) {
        DoDepersCustTestRequest request = DoDepersCustTestRequest.builder()
                .icoNum(ico)
                .fopCif(cif)
                .build();

        depersonalizeClient(request);
    }

    public void depersonalizeClientFON(String rc, String cif) {
        DoDepersCustTestRequest request = DoDepersCustTestRequest.builder()
                .rcNum(rc)
                .fonCif(cif)
                .build();

        depersonalizeClient(request);
    }

    public void depersonalizeClient(DoDepersCustTestRequest request) {
        harness.tasks().wso2().restRequest()
                .prepareRequestFromIlods("/t/training.gov/NAS/DO_DEPERS_CUST_TEST/001")
                .withHeader("Content-Type", "application/json")
                .withPojoPayload(request)
                .post()
                .andAssertStatus(200);

        harness.log("Client with RC: " + request.getRcNum() + " and ICO: " + request.getIcoNum() + " successfully depersonalized");
    }
}
