<commit_before>/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * 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 com.firebase.ui.auth;

import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.firebase.ui.auth.ui.ExtraConstants;

/**
 * A container that encapsulates the result of authenticating with an Identity Provider.
 */
public class IdpResponse implements Parcelable {
    private final String mProviderId;
    private final String mEmail;
    private final String mToken;
    private final String mSecret;
    private String mPrevUid;
    private final int mErrorCode;

    private IdpResponse(int errorCode) {
        this(null, null, null, null, null, errorCode);
    }

    private IdpResponse(
            String providerId,
            String email,
            String token,
            String secret,
            String prevUid,
            int errorCode) {
        mProviderId = providerId;
        mEmail = email;
        mToken = token;
        mSecret = secret;
        mPrevUid = prevUid;
        mErrorCode = errorCode;
    }

    /**
     * Extract the {@link IdpResponse} from the flow's result intent.
     *
     * @param resultIntent The intent which {@code onActivityResult} was called with.
     * @return The IdpResponse containing the token(s) from signing in with the Idp
     */
    @Nullable
    public static IdpResponse fromResultIntent(Intent resultIntent) {
        if (resultIntent != null) {
            return resultIntent.getParcelableExtra(ExtraConstants.EXTRA_IDP_RESPONSE);
        } else {
            return null;
        }
    }

    public static Intent getIntent(IdpResponse response) {
        return new Intent().putExtra(ExtraConstants.EXTRA_IDP_RESPONSE, response);
    }

    public static Intent getErrorCodeIntent(int errorCode) {
        return getIntent(new IdpResponse(errorCode));
    }

    /**
     * Get the type of provider. e.g. {@link AuthUI#GOOGLE_PROVIDER}
     */
    public String getProviderType() {
        return mProviderId;
    }

    /**
     * Get the email used to sign in.
     */
    public String getEmail() {
        return mEmail;
    }

    /**
     * Get the token received as a result of logging in with the specified IDP
     */
    @Nullable
    public String getIdpToken() {
        return mToken;
    }

    /**
     * Twitter only. Return the token secret received as a result of logging in with Twitter.
     */
    @Nullable
    public String getIdpSecret() {
        return mSecret;
    }

    /**
     * Only applies to developers using {@code setShouldLinkAccounts(true)}.
     * <p>
     * Get the previous user id if a conflict occurred.
     * See the <a href="https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#handling-account-link-failures">README</a>
     * for a much more detailed explanation.
     *
     * @see AuthUI.SignInIntentBuilder#setShouldLinkAccounts(boolean)
     */
    public String getPrevUid() {
        return mPrevUid;
    }

    public void setPrevUid(String uid) {
        mPrevUid = uid;
    }

    /**
     * Get the error code for a failed sign in
     */
    public int getErrorCode() {
        return mErrorCode;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mProviderId);
        dest.writeString(mEmail);
        dest.writeString(mToken);
        dest.writeString(mSecret);
        dest.writeString(mPrevUid);
        dest.writeInt(mErrorCode);
    }

    public static final Creator<IdpResponse> CREATOR = new Creator<IdpResponse>() {
        @Override
        public IdpResponse createFromParcel(Parcel in) {
            return new IdpResponse(
                    in.readString(),
                    in.readString(),
                    in.readString(),
                    in.readString(),
                    in.readInt()
            );
        }

        @Override
        public IdpResponse[] newArray(int size) {
            return new IdpResponse[size];
        }
    };

    public static class Builder implements com.firebase.ui.auth.util.Builder<IdpResponse> {<commit_msg>Fix merge mistakes<commit_after>/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * 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 com.firebase.ui.auth;

import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.firebase.ui.auth.ui.ExtraConstants;

/**
 * A container that encapsulates the result of authenticating with an Identity Provider.
 */
public class IdpResponse implements Parcelable {
    private final String mProviderId;
    private final String mEmail;
    private final String mToken;
    private final String mSecret;
    private String mPrevUid;
    private final int mErrorCode;

    private IdpResponse(int errorCode) {
        this(null, null, null, null, null, errorCode);
    }

    private IdpResponse(
            String providerId,
            String email,
            String token,
            String secret,
            String prevUid,
            int errorCode) {
        mProviderId = providerId;
        mEmail = email;
        mToken = token;
        mSecret = secret;
        mPrevUid = prevUid;
        mErrorCode = errorCode;
    }

    /**
     * Extract the {@link IdpResponse} from the flow's result intent.
     *
     * @param resultIntent The intent which {@code onActivityResult} was called with.
     * @return The IdpResponse containing the token(s) from signing in with the Idp
     */
    @Nullable
    public static IdpResponse fromResultIntent(Intent resultIntent) {
        if (resultIntent != null) {
            return resultIntent.getParcelableExtra(ExtraConstants.EXTRA_IDP_RESPONSE);
        } else {
            return null;
        }
    }

    public static Intent getIntent(IdpResponse response) {
        return new Intent().putExtra(ExtraConstants.EXTRA_IDP_RESPONSE, response);
    }

    public static Intent getErrorCodeIntent(int errorCode) {
        return getIntent(new IdpResponse(errorCode));
    }

    /**
     * Get the type of provider. e.g. {@link AuthUI#GOOGLE_PROVIDER}
     */
    public String getProviderType() {
        return mProviderId;
    }

    /**
     * Get the email used to sign in.
     */
    public String getEmail() {
        return mEmail;
    }

    /**
     * Get the token received as a result of logging in with the specified IDP
     */
    @Nullable
    public String getIdpToken() {
        return mToken;
    }

    /**
     * Twitter only. Return the token secret received as a result of logging in with Twitter.
     */
    @Nullable
    public String getIdpSecret() {
        return mSecret;
    }

    /**
     * Only applies to developers using {@code setShouldLinkAccounts(true)}.
     * <p>
     * Get the previous user id if a conflict occurred.
     * See the <a href="https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#handling-account-link-failures">README</a>
     * for a much more detailed explanation.
     *
     * @see AuthUI.SignInIntentBuilder#setShouldLinkAccounts(boolean)
     */
    public String getPrevUid() {
        return mPrevUid;
    }

    public void setPrevUid(String uid) {
        mPrevUid = uid;
    }

    /**
     * Get the error code for a failed sign in
     */
    public int getErrorCode() {
        return mErrorCode;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mProviderId);
        dest.writeString(mEmail);
        dest.writeString(mToken);
        dest.writeString(mSecret);
        dest.writeString(mPrevUid);
        dest.writeInt(mErrorCode);
    }

    public static final Creator<IdpResponse> CREATOR = new Creator<IdpResponse>() {
        @Override
        public IdpResponse createFromParcel(Parcel in) {
            return new IdpResponse(
                    in.readString(),
                    in.readString(),
                    in.readString(),
                    in.readString(),
                    in.readString(),
                    in.readInt()
            );
        }

        @Override
        public IdpResponse[] newArray(int size) {
            return new IdpResponse[size];
        }
    };

    public static class Builder implements com.firebase.ui.auth.util.Builder<IdpResponse> {
{'fraction_non_alphanumeric': 0.08309218685407194, 'fraction_numerical': 0.0018602728400165358, 'mean_word_length': 2.3357462943812477, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3015804', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2609, 'n_words': 823}