package ru.otus.mobile.component;

import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.WebElementCondition;
import io.appium.java_client.AppiumBy;
import ru.otus.mobile.page.AbsPageObject;

import java.time.Duration;

public abstract class BaseMobileComponent extends AbsPageObject {
    protected final SelenideElement root;

    protected BaseMobileComponent(SelenideElement root) {
        this.root = root;
    }

    protected SelenideElement byIdInRoot(String id) {
        return root.$(AppiumBy.id(fullIdValue(id)));
    }

    protected ElementsCollection allByIdInRoot(String id) {
        return root.$$(AppiumBy.id(fullIdValue(id)));
    }

    public BaseMobileComponent shouldBe(WebElementCondition... conditions) {
        root.shouldBe(conditions);
        return this;
    }

    public BaseMobileComponent shouldBe(WebElementCondition condition, Duration timeout) {
        root.shouldBe(condition, timeout);
        return this;
    }
}
