package com.daigou.sg.rpc.payment;

/**
 * This file is auto-generated by tgen
 * Don't change manually
 */
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.daigou.sg.rpc.BaseModule;
import com.daigou.sg.rpc.GsonUtils;
import com.daigou.sg.rpc.RpcRequest;
import com.daigou.sg.rpc.TRpc;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
public class PaymentService {
    private static final Gson gson = GsonUtils.getGsonInstance();
    private static int msgID = 1;

    private PaymentService() {
        // Constructor hidden because this is a singleton
    }

    private static String getMsgID() {
        msgID += 1;
        return Integer.toString(msgID);
    }

    public static RpcRequest AddWithdrawReqeust(final String bankName, final String account, final double amount, final String reason, final Listener<String> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        String result;
                        result = BaseModule.fromJSON(response, String.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(bankName);
                params.add(account);
                params.add(amount);
                params.add(reason);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.AddWithdrawReqeust");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest ConfirmPayments(final ArrayList<Integer> paymentIds, final Listener<Double> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        Double result;
                        result = BaseModule.fromJSON(response, Double.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(paymentIds);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.ConfirmPayments");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetCreditCardFee(final Listener<TCreditCardInfo> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TCreditCardInfo result;
                        result = BaseModule.fromJSON(response, TCreditCardInfo.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetCreditCardFee");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetPaymentDetail(final int paymentId, final Listener<TPaymentBillDetail> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TPaymentBillDetail result;
                        result = BaseModule.fromJSON(response, TPaymentBillDetail.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(paymentId);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetPaymentDetail");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetPaymentListByStatus(final String status, final int offset, final int limit, final Listener<ArrayList<TPaymentBillSummary>> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        ArrayList<TPaymentBillSummary> result;
                        result = BaseModule.fromJSONArray(response, TPaymentBillSummary.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(status);
                params.add(offset);
                params.add(limit);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetPaymentListByStatus");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetPaymentSummary(final Listener<TPaymentSummary> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TPaymentSummary result;
                        result = BaseModule.fromJSON(response, TPaymentSummary.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetPaymentSummary");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetPrepayBalance(final Listener<Double> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        Double result;
                        result = BaseModule.fromJSON(response, Double.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetPrepayBalance");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetTopUpDescription(final Listener<ArrayList<String>> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        ArrayList<String> result;
                        result = BaseModule.fromJSONArray(response, String.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetTopUpDescription");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest GetWithdrawBanks(final Listener<ArrayList<String>> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        ArrayList<String> result;
                        result = BaseModule.fromJSONArray(response, String.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.GetWithdrawBanks");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest TopUp(final String transactionNumber, final String bankName, final String telephone, final double amount, final String paymentMethod, final ArrayList<Integer> paymentIds, final String payDate, final Listener<String> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        String result;
                        result = BaseModule.fromJSON(response, String.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(transactionNumber);
                params.add(bankName);
                params.add(telephone);
                params.add(amount);
                params.add(paymentMethod);
                params.add(paymentIds);
                params.add(payDate);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.TopUp");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest UserDoCreditCardTopUp(final double total, final double creditCardFee, final ArrayList<String> paymentIds, final String telephone, final Listener<String> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        String result;
                        result = BaseModule.fromJSON(response, String.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(total);
                params.add(creditCardFee);
                params.add(paymentIds);
                params.add(telephone);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.UserDoCreditCardTopUp");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest UserGetPrimePaymentSummary(final Listener<TPrimePaymentSummary> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TPrimePaymentSummary result;
                        result = BaseModule.fromJSON(response, TPrimePaymentSummary.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.UserGetPrimePaymentSummary");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest UserPayParcelPayment(final ArrayList<Integer> paymentBillIds, final Listener<TPayParcelPaymentResult> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TPayParcelPaymentResult result;
                        result = BaseModule.fromJSON(response, TPayParcelPaymentResult.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(paymentBillIds);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.UserPayParcelPayment");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest UserPayPrimePayment(final String primeType, final Listener<TPrimePaymentResult> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TPrimePaymentResult result;
                        result = BaseModule.fromJSON(response, TPrimePaymentResult.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();
                params.add(primeType);

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.UserPayPrimePayment");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest UserRenewPrime(final Listener<TPrimePaymentResult> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TPrimePaymentResult result;
                        result = BaseModule.fromJSON(response, TPrimePaymentResult.class);

                        listener.onResponse(result);
                    } catch (Exception ex) {
                         
                        // Log.d("ex", ex.toString());
                        // Log.d("jsonObject", response);
                         
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                final ArrayList<Object> params = new ArrayList<>();

                HashMap<String, Object> msg = new HashMap<>();
                msg.put("id", getMsgID());
                msg.put("method", "Payment.UserRenewPrime");
                msg.put("params", params);

                return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }
}