package com.ss.android.ugc.aweme.services;

import X.0CB;
import X.0CH;
import X.0HH;
import X.486;
import X.487;
import X.6Is;
import X.C2133RtJ;
import X.C2160Rtk;
import X.C2162Rtm;
import X.C2449RyP;
import X.C2469Ryj;
import X.MOB;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.SmartRoute;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.account.login.twostep.TwoStepVerificationManageActivity;
import com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity;
import com.ss.android.ugc.aweme.profile.model.User;
import org.json.JSONException;
import org.json.JSONObject;

public class PasswordService extends BasePasswordService implements 6Is {
    static {
        Covode.recordClassIndex(105143);
    }

    public void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public void setPassword(Activity activity, Bundle bundle, C2449RyP ryP) {
        String str;
        super.setPassword(activity, bundle, ryP);
        SmartRoute buildRoute = SmartRouter.buildRoute((Context) activity, "//account/login/signup_or_login");
        buildRoute.withParam(bundle);
        buildRoute.withParam("next_page", C2162Rtm.CREATE_PASSWORD_FOR_PHONE.getValue());
        if (activity instanceof TwoStepVerificationManageActivity) {
            str = "open_2sv_password";
        } else {
            str = "";
        }
        buildRoute.withParam("page", str);
        buildRoute.open();
    }

    public void verifyPassword(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        super.verifyPassword(activity, str, bundle, ryP);
        SmartRoute buildRoute = SmartRouter.buildRoute((Context) activity, "//account/login/signup_or_login");
        buildRoute.withParam("enter_from", str);
        buildRoute.withParam("next_page", C2162Rtm.VERIFY_PASSWORD.getValue());
        if (bundle != null) {
            buildRoute.withParam(bundle);
        }
        buildRoute.open();
    }

    public void changePassword(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = new Bundle();
        Bundle bundle3 = bundle;
        if (bundle3 != null) {
            bundle2.putAll(bundle3);
        }
        String str3 = str;
        if (!TextUtils.isEmpty(str3)) {
            bundle2.putString("enter_from", str3);
        }
        String str4 = str2;
        if (!TextUtils.isEmpty(str4)) {
            bundle2.putString("enter_method", str4);
        }
        Activity activity2 = activity;
        C2449RyP ryP2 = ryP;
        if (C2469Ryj.LIZIZ.LJFF().isChildrenMode()) {
            super.changePassword(activity2, str3, str4, bundle2, ryP2);
            SmartRoute buildRoute = SmartRouter.buildRoute((Context) activity2, "//account/login/signup_or_login");
            buildRoute.withParam(bundle2);
            buildRoute.withParam("next_page", C2162Rtm.CHANGE_PASSWORD_FOR_CHILDREN.getValue());
            buildRoute.open();
            return;
        }
        User LJFF = C2469Ryj.LJFF();
        if (LJFF != null) {
            bundle2.putBoolean("from_changePwd", true);
            String bindPhone = LJFF.getBindPhone();
            if (!TextUtils.isEmpty(bindPhone)) {
                C2133RtJ.LIZ.LIZIZ(bundle2, bindPhone);
                bundle2.putString("enter_from_item", "change_password");
                CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.PHONE_SMS_CHANGE_PASSWORD, C2160Rtk.CHANGE_PASSWORD, bundle2, ryP2, false);
                return;
            }
            String email = LJFF.getEmail();
            if (TextUtils.isEmpty(email)) {
                bundle2.putInt("email_source", 486.DYABindEmailSourceTypeAccountManagementPassword.getValue());
                bundle2.putInt("phone_number_source", 487.DYABindPhoneNumberSourceTypeAccountManagementPassword.getValue());
                C2469Ryj.LJII().bindMobileOrEmail(activity2, str3, str4, bundle2, new PasswordService$$Lambda$1(this, bundle2, activity2, str3, str4, ryP2));
            } else if (LJFF.isEmailVerified()) {
                C2133RtJ.LIZ.LIZ(bundle2, email);
                CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.EMAIL_SMS_CHANGE_PASSWORD, C2160Rtk.CHANGE_PASSWORD, bundle2, ryP2, false);
            } else {
                bundle2.putBoolean("use_phone", true);
                bundle2.putBoolean("use_email", true);
                C2469Ryj.LJII().verifyEmail(activity2, str3, bundle2, new PasswordService$$Lambda$0(bundle2, activity2, ryP2));
            }
        }
    }

    public static final /* synthetic */ void lambda$changePassword$0$PasswordService(Bundle bundle, Activity activity, C2449RyP ryP, int i, int i2, Object obj) {
        if (i2 == 1) {
            Bundle bundle2 = bundle;
            bundle2.putAll((Bundle) obj);
            CommonFlowActivity.LJII.LIZ(activity, C2162Rtm.CHANGE_PASSWORD, C2160Rtk.CHANGE_PASSWORD, bundle2, ryP, false);
        }
    }

    public void setPasswordForMT(Activity activity, String str, String str2, String str3, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = new Bundle();
        if (bundle != null) {
            bundle2.putAll(bundle);
        }
        if (!TextUtils.isEmpty(str2)) {
            bundle2.putString("enter_from", str2);
        }
        if (!TextUtils.isEmpty(str3)) {
            bundle2.putString("enter_method", str3);
        }
        if (!TextUtils.isEmpty(str)) {
            bundle2.putString("platform", str);
        }
        CommonFlowActivity.LJII.LIZ(activity, C2162Rtm.CHANGE_PASSWORD, C2160Rtk.CHANGE_PASSWORD, bundle2, ryP, false);
    }

    public final /* synthetic */ void lambda$changePassword$1$PasswordService(Bundle bundle, Activity activity, String str, String str2, C2449RyP ryP, int i, int i2, Object obj) {
        String str3;
        Object obj2 = obj;
        if (i2 == 1) {
            Bundle bundle2 = bundle;
            if (obj2 instanceof MOB) {
                try {
                    C2133RtJ.LIZ.LIZJ(bundle2, new JSONObject(((MOB) obj2).LIZIZ).optString("ticket", ""));
                } catch (JSONException e) {
                    0HH.LIZ(e);
                }
            } else {
                bundle2.putAll((Bundle) obj2);
            }
            if (i == 7) {
                str3 = "phone";
            } else {
                str3 = "email";
            }
            setPasswordForMT(activity, str3, str, str2, bundle2, ryP);
        }
    }
}
