package org.openlmis.contract_tests.hapifhir;

import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import io.restassured.response.ValidatableResponse;
import org.apache.http.HttpStatus;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public abstract class OlmisResourceTestHelper extends BaseTestHelper {

  private static final String SEARCH_BY_IDENTIFIER_FORMAT = "%s|%s";
  private static final String BASE_URL = System.getenv("BASE_URL");

  @Override
  public JSONObject getResource(ValidatableResponse response)
      throws ParseException {
    return (JSONObject) new JSONParser().parse(response.extract().asString());
  }

  ValidatableResponse getLocation(Object resourceId, String versionNumber) {
    String queryParamValue = String.format(
        SEARCH_BY_IDENTIFIER_FORMAT,
        BASE_URL, resourceId
    );

    return doRequest()
        .queryParam("identifier", queryParamValue)
        .when()
        .get(LOCATION_URL)
        .then()
        .statusCode(HttpStatus.SC_OK)
        .body("entry", hasSize(1))
        .root("entry[0]")
        .body("resource", is(notNullValue()))
        .body("resource.meta.versionNumber", is(versionNumber))
        .root("entry[0].resource");
  }

}

@@ -852,22 +852,18 @@
  version
-Number
+Id
 ) %7B%0A    
@@ -1290,22 +1290,18 @@
 .version
-Number
+Id
 %22, is(ve
@@ -1309,14 +1309,10 @@
 sion
-Number
+Id
 ))%0A 

Revert "OLMIS-6402: Renamed versionId to versionNumber"