/*
 * Copyright 2012-2014 One Platform Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onepf.openpush;

import android.content.Context;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.onepf.openpush.util.PackageUtils;
import org.robolectric.Robolectric;

import java.util.UUID;

/**
 * Created by  Kirill Rozov on 11.09.14.
 */
class MockPushProvider extends BasePushProvider {

    public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store";
    private String mRegistrationId;
    private final boolean mAvailable;

    MockPushProvider(@NonNull Context context) {
        this(context, MockPushProvider.class.getName());
    }

    MockPushProvider(@NonNull Context context, String name) {
        this(context, name, true);
    }

    MockPushProvider(@NonNull Context context,
                     @NonNull String name,
                     boolean available) {
        this(context, name, available, DEFAULT_HOST_APP_PACKAGE);
    }

    MockPushProvider(@NonNull Context context,
                     @NonNull String name,
                     @NonNull String hotAppPackage) {
        this(context, name, true, hotAppPackage);
    }

    MockPushProvider(@NonNull Context context,
                     @NonNull String name,
                     boolean available,
                     @NonNull String hotAppPackage) {
        super(context, name, hotAppPackage);
        mAvailable = available;
    }

    @Override
    public void register() {
        mRegistrationId = UUID.randomUUID().toString();
        OpenPushHelper.getInstance(getContext())
                .onResult(new Result(getName(), mRegistrationId));
    }

    @Override
    public void unregister() {
        mRegistrationId = null;
        OpenPushHelper.getInstance(getContext())
                .onResult(new Result(getName(), mRegistrationId));
    }

    @Override
    public void onAppStateChanged() {
        mRegistrationId = null;
    }

    @Override
    public void onUnavailable() {
        mRegistrationId = null;
    }

    @Override
    public boolean isAvailable() {
        return mAvailable && PackageUtils.isInstalled(Robolectric.application, getHostAppPackage());
    }

    @Override
    public boolean isRegistered() {
        return mRegistrationId != null;
    }

    @Nullable
    @Override
    public String getRegistrationId() {
        return mRegistrationId;
    }

    @Override
    public boolean checkManifest() {
        return true;
    }
}

@@ -667,37 +667,38 @@
 ontext;%0A
-%0A
 import 
-org.jetbrains
+android.support
 .annotat
@@ -704,13 +704,12 @@
 tion
-s
 .No
-t
+n
 Null
@@ -721,21 +721,23 @@
 ort 
-org.jetbrains
+android.support
 .ann
@@ -743,17 +743,16 @@
 notation
-s
 .Nullabl
@@ -754,16 +754,17 @@
 llable;%0A
+%0A
 import o

Fix annotations in test classes.