package ru.otus.mobile.component;

import com.codeborne.selenide.SelenideElement;
import com.google.inject.Inject;
import io.appium.java_client.AppiumBy;

import static com.codeborne.selenide.appium.SelenideAppium.$;

public final class GiftFormComponent extends BaseMobileComponent {
    private final SelenideElement nameInput;
    private final SelenideElement priceInput;
    private final SelenideElement saveButton;

    @Inject
    public GiftFormComponent() {
        this($(AppiumBy.id("android:id/content")));
    }

    public GiftFormComponent(SelenideElement root) {
        super(root);
        this.nameInput = byIdInRoot("name_input");
        this.priceInput = byIdInRoot("price_input");
        this.saveButton = byIdInRoot("save_button");
    }

    public void save(String name, String price) {
        nameInput.click();
        nameInput.clear();
        nameInput.sendKeys(name);
        priceInput.click();
        priceInput.clear();
        priceInput.sendKeys(price);
        saveButton.click();
    }
}
