package ttk.commands;

import device.Pinpad;
import tlv.Tag;
import tlv.TlvItem;
import ttk.Util;

public class PurchaseWithCashback extends CommandBase {
    int amountTotal;
    int amountCash;

    public PurchaseWithCashback(Pinpad pinpad, int amountTotal, int amountCash){
        super(pinpad);
        this.amountTotal = amountTotal;
        this.amountCash = amountCash;
    }

    @Override
    protected void prepare(){
        try {
            context.add(new TlvItem(tlv.Tag.findTag("TAG_TTK_CLIENT_MID"), "CSB"));
            context.add(new TlvItem(tlv.Tag.findTag("TAG_TTK_CLIENT_AMT"), Util.intToString(amountTotal, 12)));
            //create tag
            TlvItem tagCashout = new TlvItem(Tag.findTag("TAG_CASHOUT"), Util.makeLsbDword(amountCash));
            //put it into extraData
            TlvItem extraData = new TlvItem(Tag.findTag("TAG_TTK_EXTRA_DATA"), tagCashout.getFullTLV());
            context.add(extraData);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
