package cz.moneta.test.dsl.ufo.banka.pages.products.consolidation;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Select;
import cz.moneta.test.harness.support.web.TypeInto;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;
import cz.moneta.test.harness.support.web.WebFlow;

import static cz.moneta.test.dsl.ufo.banka.pages.products.consolidation.UDC003_S002_CommitmentsInstallmentCompaniesPage.PAGE_ID;

@Wait(value = {PAGE_ID}, waitSecondsForElement = 30)
public interface UDC003_S002_CommitmentsInstallmentCompaniesPage extends WebFlow<UDC003_S002_CommitmentsInstallmentCompaniesPage>, StoreAccessor {

    String PAGE_ID = "UDC003_S002_X001";
    String INSTALLMENT_COMPANY_NAME = "UDC003_S002_C001";
    String COMMITMENT_TYPE = "UDC003_S002_C002";
    String END_COMMITMENT = "UDC003_S002_C003";
    String CREDIT_LINE_AMOUNT = "UDC003_S002_E001";
    String AMOUNT_TO_BE_PAID = "UDC003_S002_E002";
    String MONTHLY_INSTALLMENT_AMOUNT = "UDC003_S002_E003";
    String ADD_BUTTON = "UDC003_S002_B001";
    String SF_COMMITMENTS_TABLE = "UDC003_S002_G002_UfoTable";
    String CONTINUE_BUTTON = "UDC003_S002_B005";

    @Select(INSTALLMENT_COMPANY_NAME)
    UDC003_S002_CommitmentsInstallmentCompaniesPage selectInstallmentCompanyName(String installmentCompanyName);

    @Select(COMMITMENT_TYPE)
    UDC003_S002_CommitmentsInstallmentCompaniesPage selectCommitmentType(String commitmentType);

    @Select(END_COMMITMENT)
    UDC003_S002_CommitmentsInstallmentCompaniesPage selectEndCommitment(String endCommitment);

    @TypeInto(CREDIT_LINE_AMOUNT)
    UDC003_S002_CommitmentsInstallmentCompaniesPage typeIntoCreditLineAmount(int creditLineAmount);

    @TypeInto(AMOUNT_TO_BE_PAID)
    UDC003_S002_CommitmentsInstallmentCompaniesPage typeIntoAmountToBePaid(int amountToBePaid);

    @TypeInto(MONTHLY_INSTALLMENT_AMOUNT)
    UDC003_S002_CommitmentsInstallmentCompaniesPage typeIntoMonthlyInstallmentAmount(int monthlyInstallmentAmount);

    @Click(value = ADD_BUTTON, andWait = @Wait(value = SF_COMMITMENTS_TABLE, until = Until.VISIBLE))
    UDC003_S002_CommitmentsInstallmentCompaniesPage clickAddButton();

    @CustomAction
    default UDC003_S002_CommitmentsInstallmentCompaniesPage clickAddButtonAndDismissPopupWindow() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> ADD_BUTTON);
        endpoint.acceptAlert(25);
        return null;
    }

    @Click(CONTINUE_BUTTON)
    UDC003_S001_CommitmentsToConsolidationPage clickContinueButtonToConsolidationCommitmentsPage();
}