package ru.otus.mobile.page;

import com.google.inject.Inject;
import ru.otus.mobile.component.AlertDialogComponent;
import ru.otus.mobile.config.MobileConfig;
import ru.otus.mobile.config.TestAccount;

public final class LoginPage extends AbsPageObject {
    private final AlertDialogComponent alertDialog;

    @Inject
    public LoginPage(MobileConfig config, AlertDialogComponent alertDialog) {
        super(config);
        this.alertDialog = alertDialog;
    }

    public void login(TestAccount account) {
        if (!isOpened()) {
            return;
        }
        type("username_text_input", account.username());
        type("password_text_input", account.password());
        tap("log_in_button");
        alertDialog.acceptIfVisible();
    }

    public boolean isOpened() {
        return exists("username_text_input") && exists("password_text_input");
    }
}
