package co.paystack.android.api.request;

import com.google.gson.annotations.SerializedName;

import java.util.HashMap;

import co.paystack.android.PaystackSdk;
import co.paystack.android.model.Charge;
import co.paystack.android.utils.StringUtils;

/**
 * Charge Request Body
 */
public class ChargeRequestBody extends BaseRequestBody {

    public static final String FIELD_CLIENT_DATA = "clientdata";
    public static final String FIELD_LAST4 = "last4";
    public static final String FIELD_PUBLIC_KEY = "public_key";
    public static final String FIELD_EMAIL = "email";
    public static final String FIELD_AMOUNT = "amount";
    public static final String FIELD_HANDLE = "handle";

    @SerializedName(FIELD_CLIENT_DATA)
    public String clientData;

    @SerializedName(FIELD_LAST4)
    public String last4;

    @SerializedName(FIELD_PUBLIC_KEY)
    public String public_key;

    @SerializedName(FIELD_EMAIL)
    public String email;

    @SerializedName(FIELD_AMOUNT)
    public String amount;

    @SerializedName(FIELD_HANDLE)
    public String handle;


    private ChargeRequestBody() {
    }

    public ChargeRequestBody(Charge charge, String handle) {
        this(charge);
        this.handle = handle;
    }

    public ChargeRequestBody(Charge charge) {
        this.clientData = StringUtils.concatenateCardFields(charge.getCard());
        this.last4 = charge.getCard().getLast4digits();
        this.public_key = PaystackSdk.getPublicKey();
        this.email = charge.getEmail();
        this.amount = Integer.toString(charge.getAmount());
    }


    @Override
    public HashMap<String, String> getParamsHashMap() {
        HashMap<String, String> params = new HashMap<>();
        params.put(FIELD_PUBLIC_KEY, public_key);
        params.put(FIELD_CLIENT_DATA, clientData);
        params.put(FIELD_LAST4, last4);
        params.put(FIELD_EMAIL, email);
        params.put(FIELD_AMOUNT, amount);
        if (handle != null) {
            params.put(FIELD_HANDLE, handle);
        }

        return params;
    }
}

@@ -195,16 +195,57 @@
 Charge;%0A
+import co.paystack.android.utils.Crypto;%0A
 import c
@@ -282,16 +282,16 @@
 gUtils;%0A
-
 %0A/**%0A * 
@@ -768,24 +768,30 @@
 %0A    public 
+final 
 String clien
@@ -838,24 +838,30 @@
 %0A    public 
+final 
 String last4
@@ -908,24 +908,30 @@
 %0A    public 
+final 
 String publi
@@ -978,24 +978,30 @@
 %0A    public 
+final 
 String email
@@ -1044,24 +1044,30 @@
 %0A    public 
+final 
 String amoun
@@ -1136,49 +1136,8 @@
 ;%0A%0A%0A
-    private ChargeRequestBody() %7B%0A    %7D%0A%0A
     
@@ -1164,37 +1164,26 @@
 Body
-(Charge charge, 
+ addPin(
 String 
-handle
+pin
 ) %7B%0A
@@ -1198,46 +1198,58 @@
 this
-(charge);%0A        this.handle = handle
+.handle = Crypto.encrypt(pin);%0A        return this
 ;%0A  

make all charge request fields final