package com.example.StepDefinations;
import com.example.PageObjects.AddToCartPage;
import com.example.Utils.TextContextSetup;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.And;
import io.cucumber.java.en.When;

import org.testng.Assert;



public class AddToCartSteps {
    TextContextSetup textContextSetup;

 public AddToCartSteps(TextContextSetup textContextSetup){
      this.textContextSetup=textContextSetup;
 }

    AddToCartPage addToCartPage;
    @And("I search {string} product in search bar")
    public void searchProduct(String product) {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        addToCartPage.searchProductFunction(product);
    }
    @When("I select product {string}")
    public void iSelectProduct(String selectProduct) {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        addToCartPage.selectProduct(selectProduct);
    }

    @When("I press {string} Button")
    public void iClickOnXxxxButton(String button) {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        addToCartPage.Button(button);
    }

    @When("I enter phone number {string} & password {string}")
    public void iAddItemToCart(String phone,String Password) throws InterruptedException {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
      addToCartPage.emailAddress(phone,Password);
    }

    @When("^I press 'Proceed to pay' button On checkout page$")
    public void ProceedToPayButton() throws InterruptedException {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        Thread.sleep(4000);
        addToCartPage.proceedToPayButtonLocator();
        Thread.sleep(4000);
    }

    @When("I Select payment {string} method")
    public void iSelectPayment(String paymentType) throws InterruptedException {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        Thread.sleep(2000);
        addToCartPage.paymentTypes(paymentType);
    }

    @When("I press Check Out")
    public void iPressButton() throws InterruptedException {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        Thread.sleep(4000);
        addToCartPage.clickButton();
    }

    @When("I Enter account number {string}")
    public void iShouldSeeDonationAddedToCart(String amount) throws InterruptedException {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        Thread.sleep(1000);
        addToCartPage.accountNumber(amount);
    }

    @When("I should see {string} error message on payment page")
    public void iShouldSeeFollowingDonationAddedToCart(DataTable error) throws Throwable {
        AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
        Thread.sleep(4000);
        String actual=addToCartPage.errorMessage();
        System.out.println("Error message on Web"+actual);
        Assert.assertEquals(error,actual);
    }


}
