package com.daigou.sg.rpc.order;

/**
 * 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 OrderService {
    private static final Gson gson = GsonUtils.getGsonInstance();
    private static int msgID = 1;

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

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

    public static RpcRequest CancelOrder(final int orderId, final Listener<Void> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/CancelOrder",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {if (listener != null) {
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("orderId", orderId);

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

    public static RpcRequest GetArrivedOrderSummary(final String originCode, final String warehouseCode, final Listener<ArrayList<TArrivedOrderSummary>> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/GetArrivedOrderSummary",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        ArrayList<TArrivedOrderSummary> result;
                        result = BaseModule.doFromJSONArray(response, TArrivedOrderSummary.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("originCode", originCode);
                msg.put("warehouseCode", warehouseCode);

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

    public static RpcRequest GetArrivedOrders(final String originCode, final String warehouseCode, final String shipmentTypeCode, final Listener<TReadyToShipSummary> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/GetArrivedOrders",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TReadyToShipSummary result;
                        result = BaseModule.doFromJSON(response, TReadyToShipSummary.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("originCode", originCode);
                msg.put("warehouseCode", warehouseCode);
                msg.put("shipmentTypeCode", shipmentTypeCode);

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

    public static RpcRequest GetOrderDetail(final int orderId, final Listener<TOrderDetail> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/GetOrderDetail",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TOrderDetail result;
                        result = BaseModule.doFromJSON(response, TOrderDetail.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("orderId", orderId);

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

    public static RpcRequest GetOrderListByStatus(final String originCode, final String orderStatus, final String warehouseCode, final Listener<ArrayList<TOrder>> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/GetOrderListByStatus",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        ArrayList<TOrder> result;
                        result = BaseModule.doFromJSONArray(response, TOrder.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("originCode", originCode);
                msg.put("orderStatus", orderStatus);
                msg.put("warehouseCode", warehouseCode);

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

    public static RpcRequest GetOrderSummary(final String originCode, final Listener<TOrderSummary> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/GetOrderSummary",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TOrderSummary result;
                        result = BaseModule.doFromJSON(response, TOrderSummary.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("originCode", originCode);

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

    public static RpcRequest PayForCheckOut(final boolean authorizeForBalance, final String originCode, final Listener<Integer> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/PayForCheckOut",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        Integer result;
                        result = BaseModule.doFromJSON(response, Integer.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("authorizeForBalance", authorizeForBalance);
                msg.put("originCode", originCode);

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

    public static RpcRequest ReplyOrderRemark(final int orderId, final int orderRemarkParentId, final String remark, final String pictures, final Listener<Void> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/ReplyOrderRemark",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {if (listener != null) {
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("orderId", orderId);
                msg.put("orderRemarkParentId", orderRemarkParentId);
                msg.put("remark", remark);
                msg.put("pictures", pictures);

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

    public static RpcRequest UpdateOrder(final int orderId, final int shipmentTypeId, final String warehouseCode, final double internalShipmentFee, final boolean insured, final String productRemark, final Listener<Void> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/UpdateOrder",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {if (listener != null) {
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("orderId", orderId);
                msg.put("shipmentTypeId", shipmentTypeId);
                msg.put("warehouseCode", warehouseCode);
                msg.put("internalShipmentFee", internalShipmentFee);
                msg.put("insured", insured);
                msg.put("productRemark", productRemark);

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

    public static RpcRequest UserAddToCartByOrderId(final int orderId, final Listener<Void> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/UserAddToCartByOrderId",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {if (listener != null) {
                        listener.onResponse(null);
                    }
                }
            }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                listener.onResponse(null);
            }
        }) {
            @Override
            public byte[] getBody() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("orderId", orderId);

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

    public static RpcRequest UserChangeEZShipping(final boolean ezShipping, final Listener<TEzShipping> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/UserChangeEZShipping",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TEzShipping result;
                        result = BaseModule.doFromJSON(response, TEzShipping.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("ezShipping", ezShipping);

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

    public static RpcRequest UserGetEZShippingStatus(final Listener<TEzShipping> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/UserGetEZShippingStatus",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        TEzShipping result;
                        result = BaseModule.doFromJSON(response, TEzShipping.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() {
                return "".getBytes(Charset.forName("UTF-8"));
            }
        };
        TRpc.getQueue().add(req);
        return req;
    }

    public static RpcRequest WrapOrderToPackage(final String originCode, final String warehouseCode, final String shipmentTypeCode, final Listener<Integer> listener) {
        RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Order/WrapOrderToPackage",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        Integer result;
                        result = BaseModule.doFromJSON(response, Integer.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() {
                HashMap<String, Object> msg = new HashMap<String, Object>();
                msg.put("originCode", originCode);
                msg.put("warehouseCode", warehouseCode);
                msg.put("shipmentTypeCode", shipmentTypeCode);

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