<commit_before>package de.fau.cs.mad.fablab.android.model;

import android.os.Handler;

import java.util.ArrayList;
import java.util.List;

import de.fau.cs.mad.fablab.android.model.entities.CartEntry;
import de.fau.cs.mad.fablab.android.model.events.CheckoutStatusChangedEvent;
import de.fau.cs.mad.fablab.android.model.util.CancellableCallback;
import de.fau.cs.mad.fablab.rest.core.CartEntryServer;
import de.fau.cs.mad.fablab.rest.core.CartServer;
import de.fau.cs.mad.fablab.rest.core.CartStatus;
import de.fau.cs.mad.fablab.rest.myapi.CartApi;
import de.greenrobot.event.EventBus;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class CheckoutModel {
    private CartModel mCartModel;
    private CartApi mCartApi;
    private PushModel mPushModel;
    private EventBus mEventBus = EventBus.getDefault();

    private Handler mCartStatusHandler = new Handler();
    private CartStatusRunner mCartStatusRunner;
    private CancellableCallback<Response> mCartCreationCallback;

    private CartStatus mCheckoutStatus;
    private String mCartCode;

    public CheckoutModel(CartModel cartModel, CartApi cartApi, PushModel pushModel) {
        mCartModel = cartModel;
        mCartApi = cartApi;
        mPushModel = pushModel;

        mEventBus.register(this);
    }

    public CartStatus getStatus() {
        return mCheckoutStatus;
    }

    public void startCheckout(final String cartCode) {
        mCheckoutStatus = CartStatus.SHOPPING;

        CartServer cartServer = new CartServer();
        cartServer.setCartCode(cartCode);
        cartServer.setStatus(CartStatus.PENDING);
        cartServer.setPushId(mPushModel.getPushId());
        List<CartEntryServer> cartEntriesServer = new ArrayList<>();
        for (CartEntry entry : mCartModel.getCartEntries()) {
            cartEntriesServer.add(new CartEntryServer(entry.getProduct().getProductId(),
                    cartServer, entry.getAmount()));
        }
        cartServer.setItems(cartEntriesServer);

        mCartCreationCallback = new CancellableCallback<Response>() {
<commit_msg>PlatformEnum included to  CartToServer at checkoutprocess<commit_after>package de.fau.cs.mad.fablab.android.model;

import android.os.Handler;

import java.util.ArrayList;
import java.util.List;

import de.fau.cs.mad.fablab.android.model.entities.CartEntry;
import de.fau.cs.mad.fablab.android.model.events.CheckoutStatusChangedEvent;
import de.fau.cs.mad.fablab.android.model.util.CancellableCallback;
import de.fau.cs.mad.fablab.rest.core.CartEntryServer;
import de.fau.cs.mad.fablab.rest.core.CartServer;
import de.fau.cs.mad.fablab.rest.core.CartStatus;
import de.fau.cs.mad.fablab.rest.core.PlatformType;
import de.fau.cs.mad.fablab.rest.myapi.CartApi;
import de.greenrobot.event.EventBus;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class CheckoutModel {
    private CartModel mCartModel;
    private CartApi mCartApi;
    private PushModel mPushModel;
    private EventBus mEventBus = EventBus.getDefault();

    private Handler mCartStatusHandler = new Handler();
    private CartStatusRunner mCartStatusRunner;
    private CancellableCallback<Response> mCartCreationCallback;

    private CartStatus mCheckoutStatus;
    private String mCartCode;

    public CheckoutModel(CartModel cartModel, CartApi cartApi, PushModel pushModel) {
        mCartModel = cartModel;
        mCartApi = cartApi;
        mPushModel = pushModel;

        mEventBus.register(this);
    }

    public CartStatus getStatus() {
        return mCheckoutStatus;
    }

    public void startCheckout(final String cartCode) {
        mCheckoutStatus = CartStatus.SHOPPING;

        CartServer cartServer = new CartServer();
        cartServer.setCartCode(cartCode);
        cartServer.setStatus(CartStatus.PENDING);
        cartServer.setPushToken(mPushModel.getPushId());
        cartServer.setPlatformType(PlatformType.ANDROID);
        List<CartEntryServer> cartEntriesServer = new ArrayList<>();
        for (CartEntry entry : mCartModel.getCartEntries()) {
            cartEntriesServer.add(new CartEntryServer(entry.getProduct().getProductId(),
                    cartServer, entry.getAmount()));
        }
        cartServer.setItems(cartEntriesServer);

        mCartCreationCallback = new CancellableCallback<Response>() {

{'fraction_non_alphanumeric': 0.09340031970769581, 'fraction_numerical': 0.0, 'mean_word_length': 3.8720800889877642, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1464963', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1304, 'n_words': 232}