package com.namelessmc.java_api.modules.store;

import com.google.gson.JsonObject;
import com.namelessmc.java_api.exception.NamelessException;
import com.namelessmc.java_api.NamelessUser;
import com.namelessmc.java_api.RequestHandler;
import com.namelessmc.java_api.modules.ModuleNames;

public class StoreUser {

	private final NamelessUser user;
	private final RequestHandler requests;

	public StoreUser(NamelessUser user) throws NamelessException {
		this.user = user;
		this.requests = user.api().requests();
		user.api().ensureModuleInstalled(ModuleNames.STORE);
	}

	@Deprecated
	public void addCredits(float creditsToAdd) throws NamelessException {
		JsonObject body = new JsonObject();
		body.addProperty("credits", creditsToAdd);
		this.requests.post("users/" + this.user.userTransformer() + "/add-credits", body);
	}

	public void addCredits(int cents) throws NamelessException {
		// Module does not support adding cents yet
		this.addCredits(cents * 100f);
	}

	@Deprecated
	public void removeCredits(float creditsToRemove) throws NamelessException {
		JsonObject body = new JsonObject();
		body.addProperty("credits", creditsToRemove);
		this.requests.post("users/" + this.user.userTransformer() + "/remove-credits", body);
	}

	public void removeCredits(int cents) throws NamelessException {
		// Module does not support removing cents yet
		this.removeCredits(cents * 100f);
	}

	@Deprecated
	public float credits() throws NamelessException {
		JsonObject response = this.requests.get("users/" + this.user.userTransformer() + "/credits");
		return response.get("credits").getAsFloat();
	}

	public int creditsCents() throws NamelessException {
		JsonObject response = this.requests.get("users/" + this.user.userTransformer() + "/credits");
		return response.get("cents").getAsInt();
	}

}

@@ -41,16 +41,50 @@
 store;%0A%0A
+import com.google.gson.JsonArray;%0A
 import c
@@ -315,16 +315,40 @@
 Names;%0A%0A
+import java.util.List;%0A%0A
 public c
@@ -1854,10 +1854,773 @@
 ();%0A%09%7D%0A%0A
+%09public void createOrder(StoreCustomer purchaser, StoreCustomer recipient, List%3CStoreProduct%3E products) throws NamelessException %7B%0A%09%09JsonArray productIds = new JsonArray(products.size());%0A%09%09for (int i = 0; i %3C products.size(); i++) %7B%0A%09%09%09productIds.add(products.get(i).id());%0A%09%09%7D%0A%09%09this.createOrder(purchaser.id(), recipient.id(), productIds);%0A%09%7D%0A%0A%09public void createOrder(int purchaserCustomerId, int recipientCustomerId, JsonArray productIds) throws NamelessException %7B%0A%09%09JsonObject body = new JsonObject();%0A%09%09body.addProperty(%22user%22, this.user.userTransformer());%0A%09%09body.addProperty(%22customer%22, purchaserCustomerId);%0A%09%09body.addProperty(%22recipient%22, recipientCustomerId);%0A%09%09body.add(%22products%22, productIds);%0A%09%09this.requests.post(%22store/order/create%22, body);%0A%09%7D%0A%0A
 %7D%0A

Add methods to create order