package cz.moneta.test.dsl.ufo.banka.pages.cards.credit;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.loans.CAS001_S001_ScoringPage;
import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.NKK019_S001_DeclipRequestPage.NKK019_S001_PAGE_ID_XPATH;

@Wait(value = NKK019_S001_PAGE_ID_XPATH, by = Lookup.XPATH)
public interface NKK019_S001_DeclipRequestPage extends WebFlow<NKK019_S001_DeclipRequestPage>, StoreAccessor {

    String NKK019_S001_PAGE_ID_XPATH = "//div[text()='NKK019_S001']";
    String CONTINUE_BUTTON = "NKK019_S001_B002";
    String NEW_CREDIT_AMOUNT_INPUT = "NKK019_S001_E005";
    String NEW_LIMIT_BANK_INPUT = "NKK019_S001_E006";
    String NEW_LIMIT_MOTO_INPUT = "NKK019_S001_E007";
    String NEW_LIMIT_INT_INPUT = "NKK019_S001_E010";
    String FIRST_CARD_RADIO = "NKK019_S001_G001-0";
    String CHANGE_LIMITS_BUTTON = "NKK019_S001_B001";

    @Click(CONTINUE_BUTTON)
    CAS001_S001_ScoringPage clickContinueToScoringPage();

    @TypeInto(clear = true, value = NEW_CREDIT_AMOUNT_INPUT)
    NKK019_S001_DeclipRequestPage fillNewCreditAmount(String newCreditAmount);

    @TypeInto(clear = true, value = NEW_LIMIT_BANK_INPUT)
    @TypeInto(clear = true, value = NEW_LIMIT_MOTO_INPUT)
    @TypeInto(clear = true, value = NEW_LIMIT_INT_INPUT)
    NKK019_S001_DeclipRequestPage fillNewLimits(String newLimitBank, String newLimitMoto, String newLimitInt);

    @Click(FIRST_CARD_RADIO)
    NKK019_S001_DeclipRequestPage clickSelectFirstCard();

    @Click(value = CHANGE_LIMITS_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    NKK019_S001_DeclipRequestPage clickChangeLimits();

    @CustomAction
    default NKK019_S001_DeclipRequestPage getAndFillEditedLowerAmount(Harness harenss) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String currentAmount = harenss.get("TOTAL_CREDIT_STORE");
        String editedAmount = currentAmount.replace(" ", "").replace(",00", "");
        Long higherEditedAmount = Long.parseLong(editedAmount) - 5000;
        endpoint.type(() -> NEW_CREDIT_AMOUNT_INPUT, higherEditedAmount.toString(), true);
        return null;
    }
}