package com.samourai.wallet.whirlpool;

import android.content.Context;

import com.samourai.wallet.SamouraiWallet;

import org.json.JSONException;
import org.json.JSONObject;

public class WhirlpoolMeta {

    public final static double WHIRLPOOL_FEE_RATE_POOL_DENOMINATION = 0.05;

    private final static int WHIRLPOOL_PREMIX_ACCOUNT = Integer.MAX_VALUE - 2;
    private final static int WHIRLPOOL_POSTMIX = Integer.MAX_VALUE - 1;

    private static int preIdx  = 0;
    private static int postIdx  = 0;

    private static WhirlpoolMeta instance = null;

    private static Context context = null;

    private WhirlpoolMeta() { ; }

    public static WhirlpoolMeta getInstance(Context ctx) {

        context = ctx;

        if(instance == null) {
            instance = new WhirlpoolMeta();
        }

        return instance;
    }

    public int getWhirlpoolPremixAccount() {
        return WHIRLPOOL_PREMIX_ACCOUNT;
    }

    public int getWhirlpoolPostmix() {
        return WHIRLPOOL_POSTMIX;
    }

    public int getPreIdx() {
        return preIdx;
    }

    public void setPreIdx(int idx) {
        WhirlpoolMeta.preIdx = idx;
    }

    public int getPostIdx() {
        return postIdx;
    }

    public void setPostIdx(int idx) {
        WhirlpoolMeta.postIdx = idx;
    }

    public String getDefaultFeeAddress()    {

        if(SamouraiWallet.getInstance().isTestNet())    {
            return "tb1qhq028k8qey83ylmc003qdtt7mhp76a5cgk5htj";
        }
        else    {
            return "bc1qxya59zn6fgenfls0pedt0xqkagd33fcfc5s04n";
        }

    }

    public JSONObject toJSON() {

        JSONObject jsonPayload = new JSONObject();
        try {

            jsonPayload.put("pre_index", preIdx);
            jsonPayload.put("post_index", postIdx);

        }
        catch(JSONException je) {
            ;
        }

        return jsonPayload;
    }

    public void fromJSON(JSONObject jsonPayload) {

        try {

            if(jsonPayload.has("pre_index"))    {
                preIdx = jsonPayload.getInt("pre_index");
            }
            if(jsonPayload.has("post_index"))    {
                postIdx = jsonPayload.getInt("post_index");
            }

        }
        catch(JSONException ex) {
            throw new RuntimeException(ex);
        }

    }

}

@@ -433,82 +433,8 @@
 1;%0A%0A
-    private static int preIdx  = 0;%0A    private static int postIdx  = 0;%0A%0A
     
@@ -471,32 +471,32 @@
 nstance = null;%0A
+
 %0A    private sta
@@ -938,290 +938,8 @@
  %7D%0A%0A
-    public int getPreIdx() %7B%0A        return preIdx;%0A    %7D%0A%0A    public void setPreIdx(int idx) %7B%0A        WhirlpoolMeta.preIdx = idx;%0A    %7D%0A%0A    public int getPostIdx() %7B%0A        return postIdx;%0A    %7D%0A%0A    public void setPostIdx(int idx) %7B%0A        WhirlpoolMeta.postIdx = idx;%0A    %7D%0A%0A
     
@@ -1296,24 +1296,35 @@
 ONObject();%0A
+        /*%0A
         try 
@@ -1330,111 +1330,8 @@
  %7B%0A%0A
-            jsonPayload.put(%22pre_index%22, preIdx);%0A            jsonPayload.put(%22post_index%22, postIdx);%0A%0A
     
@@ -1385,32 +1385,43 @@
      ;%0A        %7D
+%0A        */
 %0A%0A        return
@@ -1489,24 +1489,35 @@
 Payload) %7B%0A%0A
+        /*%0A
         try 
@@ -1523,256 +1523,8 @@
  %7B%0A%0A
-            if(jsonPayload.has(%22pre_index%22))    %7B%0A                preIdx = jsonPayload.getInt(%22pre_index%22);%0A            %7D%0A            if(jsonPayload.has(%22post_index%22))    %7B%0A                postIdx = jsonPayload.getInt(%22post_index%22);%0A            %7D%0A%0A
     
@@ -1607,16 +1607,16 @@
 on(ex);%0A
-
         
@@ -1608,27 +1608,38 @@
 n(ex);%0A        %7D
+%0A        */
 %0A%0A    %7D%0A%0A%7D%0A

remove dead code