import app.musicplatform.client.ApiClient;
import org.json.JSONObject;

public class PrivacyIntegration {
    public static void main(String[] args) throws Exception {
        JSONObject fixture = new JSONObject(new String(System.in.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8));
        ApiClient client = new ApiClient(args[0]);
        client.login(fixture.getString("email"), fixture.getString("password"));
        String route = "/api/v1/privacy/deletion-request";
        if (!client.get(route).isNull("request")) throw new AssertionError("Expected no initial request");
        JSONObject confirm = new JSONObject().put("confirm", true);
        String id = client.request("POST", route, confirm, null).getJSONObject("request").getString("id");
        if (!id.equals(client.request("POST", route, confirm, null).getJSONObject("request").getString("id"))) {
            throw new AssertionError("Retry changed the deletion receipt");
        }
        if (!id.equals(client.get(route).getJSONObject("request").getString("id"))) {
            throw new AssertionError("Saved receipt does not match submission");
        }
        client.logout();
        System.out.println(id);
    }
}
