aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/chesttracker/data/HyBazaarData.java
blob: 17ffcf1f2213393ac0144739a9ae09baa85c8e7a (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.data;

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;
            }
        }
    }
}