package cz.moneta.test.dsl.ufo.cb.landing;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.cb.landing.proposal.pages.JAN451_S001_FinancialSheetsSignPost;
import cz.moneta.test.dsl.ufo.cb.landing.proposal.pages.KOM461_S001_Rating;
import cz.moneta.test.dsl.ufo.cb.landing.proposal.pages.PRC401_S002_Pricing;
import cz.moneta.test.dsl.ufo.cb.landing.proposal.pages.VST403_S001_Relations;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.exception.HarnessException;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ufo.cb.landing.IKL402_S001_ClientPage.RELATIONS_BUTTON;

@Wait(value = RELATIONS_BUTTON, until = Until.VISIBLE)
public interface IKL402_S001_ClientPage extends WebFlow<IKL402_S001_ClientPage>, StoreAccessor {

    String INVOLVEMENT_CALCULATION_TIME_KEY = "INVOLVEMENT_CALCULATION_TIME";
    String FULL_NAME_KEY = "FULL_NAME";
    String FULL_NAME_DIV = "XXX408_T001_L052";
    String RETURN_TO_SEARCH_BUTTON = "XXX408_T001_B040";
    String TASKS_BUTTON = "IKL402_S001_S001";
    String CLIENT_CARD_BUTTON = "IKL402_S001_I001";
    String RELATIONS_BUTTON = "IKL402_S001_I031";
    String FINANCIAL_SHEETS_BUTTON = "IKL402_S001_I002";
    String DOCUMENTS_BUTTON = "IKL402_S001_I005";
    String PRICING_BUTTON = "IKL402_S001_S006";
    String COLLATERAL_BUTTON = "IKL402_S001_S008";
    String CHECKLISTS_BUTTON = "IKL402_S001_B018";
    String CLIENT_RECORD_BUTTON = "IKL402_S001_B019";
    String RATING_LGD_BUTTON = "IKL402_S001_B046";
    String ALL_TRADES_BUTTON = "IKL402_S001_B029";
    String IN_PROGRESS_TRADES_INPUT = "IKL402_S001_G001-0";
    String BLACK_LISTS_RELEVANT_PERSONS_BUTTON = "IKL402_S001_B030";
    String CHAT_BUTTON = "IKL402_S001_B035";
    String LIST_PROPOSALS_INPUT = "IKL402_S001_G001";
    String ICO_LABEL = "XXX408_T001_L091";
    String CIF_LABEL = "XXX408_T001_L020";
    String DETAIL_CLIENT_INFO_BUTTON = "XXX408_T001_B018";
    String CLOSE_DETAIL_CLIENT_INFO_BUTTON = "XXX408_T001_B021";
    String OM_DIV = "XXX408_T001_L102";
    String CLIENTS_BANKER_DIV = "XXX408_T001_L032";
    String ADMINISTRATOR_DIV = "XXX408_T001_L099";
    String CLIENT_ID_LABEL = "XXX408_T001_L075";
    String RC_LABEL = "XXX408_T001_L089";
    String NEW_PROPOSAL = "IKL402_S001_B023";
    String CALCULATE_BUTTON = "IKL402_S001_B006";
    String PROPOSE_ELEMENT = "//table[@id='IKL402_S001_G001_UfoTable']//td[3]";
    String REG_NUM_ELEMENT = "//table[@id='IKL402_S001_G001_UfoTable']//td[2]";
    String ACCOUNT_NUM_ELEMENT = "//table[@id='IKL402_S001_G004_UfoTable']//td[4]";
    String CALCULATION_TIME_DIV = "IKL402_S001_L023";
    String KO_CRITERIA = "IKL402_S001_I024";

    @Click(RETURN_TO_SEARCH_BUTTON)
    SME401_S001_SearchPage returnToSearchPage();

    @CheckElementContent(RC_LABEL)
    IKL402_S001_ClientPage checkRc(String rc);

    @CheckElementContent(CLIENT_ID_LABEL)
    IKL402_S001_ClientPage checkClientId(String clientId);

    @CheckElementContent(ICO_LABEL)
    IKL402_S001_ClientPage checkIco(String ico);

    @CheckElementContent(CIF_LABEL)
    IKL402_S001_ClientPage checkCif(String cif);

    @CheckElementContent(value = ACCOUNT_NUM_ELEMENT, by = Lookup.XPATH)
    IKL402_S001_ClientPage checkAccNum(String accNum);

    @CheckElementContent(value = REG_NUM_ELEMENT, by = Lookup.XPATH)
    IKL402_S001_ClientPage checkRegNum(String regNum);

    @CheckElementContent(value = PROPOSE_ELEMENT, by = Lookup.XPATH)
    IKL402_S001_ClientPage checkProposalId(String proposalId);

    @Click(IN_PROGRESS_TRADES_INPUT)
    IKL402_S001_ClientPage checkProduct();

    @Click(CLIENT_CARD_BUTTON)
    ZKL421_S001_ClientCardPage clickClientCard();

    @Click(ALL_TRADES_BUTTON)
    IKL406_S001_AllTradesPage clickAllTrades();

    @Click(BLACK_LISTS_RELEVANT_PERSONS_BUTTON)
    SOU401_S001_RelevantPersonsBlackListsPage clickRelevantPersonsBlackLists();

    @Click(CHAT_BUTTON)
    CHT401_S001_ChatPage clickChat();

    @Click(value = DETAIL_CLIENT_INFO_BUTTON, andWait = @Wait(value = OM_DIV, until = Until.VISIBLE))
    IKL402_S001_ClientPage clickDetailedClientInfo();

    @Click(CLOSE_DETAIL_CLIENT_INFO_BUTTON)
    IKL402_S001_ClientPage clickCloseDetailedClientInfo();

    @CustomAction
    default IKL402_S001_ClientPage checkOMIsNotEmpty() {
        UfoEndpoint ufoEndpoint = getEndpoint(UfoEndpoint.class);
        String omText = ufoEndpoint.getText(OM_DIV);
        Assertions.assertNotEquals("", omText);
        return null;
    }

    @CustomAction
    default IKL402_S001_ClientPage checkClientsBankerIsNotEmpty() {
        UfoEndpoint ufoEndpoint = getEndpoint(UfoEndpoint.class);
        String clientsBanker = ufoEndpoint.getText(CLIENTS_BANKER_DIV);
        Assertions.assertNotEquals("", clientsBanker);
        return null;
    }

    @CustomAction
    default IKL402_S001_ClientPage checkAdministratorIsNotEmpty() {
        UfoEndpoint ufoEndpoint = getEndpoint(UfoEndpoint.class);
        String administratorText = ufoEndpoint.getText(ADMINISTRATOR_DIV);
        Assertions.assertNotEquals("", administratorText);
        return null;
    }

    @Click(DOCUMENTS_BUTTON)
    DMS401_S002_DocumentsPage clickDocuments();

    @CheckElementPresent(LIST_PROPOSALS_INPUT)
    IKL402_S001_ClientPage checkElementListProposals();

    @Click(NEW_PROPOSAL)
    AKV401_S001_Opportunities clickNewProposal();

    @Click(CALCULATE_BUTTON)
    IKL402_S010_WaitingForCalculationPage calculateInvolvement();

    @Click(RELATIONS_BUTTON)
    VST403_S001_Relations clickRelationsButton();

    @Click(FINANCIAL_SHEETS_BUTTON)
    JAN451_S001_FinancialSheetsSignPost clickFinancialSheets();

    @Click(TASKS_BUTTON)
    DSB451_S001_SummaryOfTasks clickTasks();

    @Click(PRICING_BUTTON)
    PRC401_S002_Pricing clickPricing();

    @Click(COLLATERAL_BUTTON)
    ZST419_S001_Collateral clickCollateral();

    @Click(CLIENT_RECORD_BUTTON)
    EVD401_S001_SearchClientRecords clickClientRecord();

    @Click(CHECKLISTS_BUTTON)
    CHL405_S001_Checklists clickChecklists();

    @Click(RATING_LGD_BUTTON)
    KOM461_S001_Rating clickRatingLgd();

    @StoreElementContent(storeKey = INVOLVEMENT_CALCULATION_TIME_KEY, value = CALCULATION_TIME_DIV)
    IKL402_S001_ClientPage storeLastInvolvementCalculationTime();

    @StoreElementContent(storeKey = FULL_NAME_KEY, value = FULL_NAME_DIV)
    IKL402_S001_ClientPage storeClientFullName();

    @CustomAction
    default IKL402_S001_ClientPage checkChangeOfCalculatedTime(String previousCalculatedTime) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String calculatedTime = endpoint.getText(CALCULATION_TIME_DIV);
        if (calculatedTime.equals(previousCalculatedTime)) {
            throw new HarnessException("Calculated time did not change");
        }
        return null;
    }

    @CustomAction
    default IKL402_S001_ClientPage checkCalculatedTimeNotEmpty() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String calculatedTime = endpoint.getText(CALCULATION_TIME_DIV);
        Assertions.assertNotEquals("", calculatedTime);
        return null;
    }

    @Click(KO_CRITERIA)
    IKL402_S001_ClientPage clickKOCriteria();

    @CustomAction
    default AUT402_S001_KOCriteriaListPage switchToOtherWindow() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.switchToOtherWindow(15, 2);
        return null;
    }
}
