aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/chesttracker/HyBazaarData.java
blob: 38aba6fca42db6481196fcec7134624e7a28f7d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package de.cowtipper.cowlection.chesttracker;

import com.google.gson.annotations.SerializedName;

import java.util.Map;

@SuppressWarnings("unused")
public class HyBazaarData {
    private boolean success;
    private long lastUpdated;
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
    private Map<String, Product> products;

    public boolean isSuccess() {
        return success;
    }

    /**
     * Returns {@link Product} from bazaar reply.
     * Returns null if product does not exist
     *
     * @param productId product in bazaar
     * @return instance of Product
     */
    public Product getProduct(String productId) {
        return products.get(productId);
    }

    /**
     * Refresh only allowed once per minute
     */
    public boolean allowRefreshData() {
        return (System.currentTimeMillis() - lastUpdated) > 60000;
    }

    public static class Product {
        @SerializedName("quick_status")
        private Status quickStatus;

        public double getInstantSellPrice() {
            return quickStatus.getSellPrice();
        }

        public double getSellOfferPrice() {
            return quickStatus.getBuyPrice();
        }

        public static class Status {
            private double sellPrice;
            private double buyPrice;

            public double getSellPrice() {
                return sellPrice;
            }

            public double getBuyPrice() {
                return buyPrice;
            }
        }
    }
}