package io.synor.dex;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * Farms and staking sub-client
 */
public class FarmsClient {
    private final SynorDex dex;

    FarmsClient(SynorDex dex) {
        this.dex = dex;
    }

    public CompletableFuture<List<Farm>> listFarms() {
        return dex.getList("/farms", Farm.class);
    }

    public CompletableFuture<Farm> getFarm(String farmId) {
        return dex.get("/farms/" + farmId, Farm.class);
    }

    public CompletableFuture<FarmPosition> stake(StakeParams params) {
        Map<String, Object> body = new HashMap<>();
        body.put("farm", params.getFarm());
        body.put("amount", params.getAmount().toString());
        return dex.post("/farms/stake", body, FarmPosition.class);
    }

    public CompletableFuture<FarmPosition> unstake(String farm, BigInteger amount) {
        Map<String, Object> body = new HashMap<>();
        body.put("farm", farm);
        body.put("amount", amount.toString());
        return dex.post("/farms/unstake", body, FarmPosition.class);
    }

    public CompletableFuture<ClaimRewardsResult> claimRewards(String farm) {
        Map<String, Object> body = new HashMap<>();
        body.put("farm", farm);
        return dex.post("/farms/claim", body, ClaimRewardsResult.class);
    }

    public CompletableFuture<List<FarmPosition>> getMyFarmPositions() {
        return dex.getList("/farms/positions", FarmPosition.class);
    }
}
