package com.avg.zaap.crashlibrary;

import android.content.Context;
import android.os.RemoteException;

import com.avg.zaap.crashlibrary.core.logger.CrashLogger;

/**
 * This class serves as the service binder for the {@link CrashReportingService}.
 * <p/>
 * Created by marek.osvald on 3.5.2016.
 */
public class CrashReportingServiceBinder extends ICrashServiceCommunicator.Stub {

    private static final String TAG = CrashReportingServiceBinder.class.getName();

    private ICrashReporter mCrashReporter;
    private ICrashPublishingDelegate mCrashPublishingDelegate;

    /**
     * Parametric constructor. Sets the Android context and the crash reporter.
     *
     * @param context       Android context
     * @param crashReporter crash reporter to be set
     */
    public CrashReportingServiceBinder(Context context, ICrashReporter crashReporter) {
        this(context, crashReporter, new CrashReportingServiceBinderFactory());
    }

    /**
     * Parametric constructor. Sets the Android context, crash reporter.
     *
     * @param context       Android context
     * @param crashReporter crash reporter to delegate the report to
     * @param factory       dependency factory to be used
     */
    public CrashReportingServiceBinder(Context context, ICrashReporter crashReporter, ICrashReportingServiceBinderFactory factory) {
        super();
        mCrashReporter = crashReporter;
        mCrashPublishingDelegate = factory.getCrashPublishingDelegate(context);
    }

    @Override
    public void reportAndroidCrash(ReportData reportData) throws RemoteException {
        CrashLogger.d(TAG, "reportAndroidCrash() called");
        mCrashReporter.reportAndroidCrash(reportData);
    }

    @Override
    public void publishAndroidCrash(ReportData reportData, ICrashServiceCallback callback) throws RemoteException {
        CrashLogger.d(TAG, "publishAndroidCrash() called");
        mCrashPublishingDelegate.publishCrash(reportData, callback);
    }

}
