package cz.moneta.test.dsl.brokerportal.contractdetail;

import cz.moneta.test.dsl.brokerportal.contract.ValuationPage;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.brokerportal.contractdetail.ContractDetailPage.BUTTON_SHOW_CALCULATION;

@Wait(BUTTON_SHOW_CALCULATION)
public interface ContractDetailPage extends WebFlow<ContractDetailPage> {
    String BUTTON_VALUATE = "//button[@id='canAppraise']";
    String BUTTON_ASSIGN_PROCESSING_TEAM = "//button[@id='canAssignProcessingTeam']";
    String BUTTON_SHOW_CALCULATION = "//button[@id='canShowCalculation']";
    String BUTTON_CHECKLIST = "//ul/li/button[text()='Checklist']";

    String EDIT_CONTACT_DETAILS_BUTTON = "//div[@class='c-card__header']//button[@data-testid='Link']";
    String CHECKLIST_DIV = "//h4[text()='Checklist - dokumenty požadované ke schválení']/parent::div";
    String CHECKLIST_LOADER = "//div[contains(@class, 'loader')]";
    String CHECKLIST_DOC = CHECKLIST_DIV + "//h5[text()='%s']";
    String CHECKLIST_DOC_FILE_UPLOAD = "(" + CHECKLIST_DIV + "//input[@type='file'])[1]";
    String CHECKLIST_DOC_UPLOAD_BUTTON = CHECKLIST_DIV + "//button[text()='Nahrát']";
    String CHECKLIST_DOC_UPLOAD_LOADER = CHECKLIST_DIV + "//button[text()='Nahrát'][contains(@class, 'loading')]";
    String CHECKLIST_DOC_UPLOADED = CHECKLIST_DIV + "//small[contains(text(), 'Dokument byl nahrán')]";

    @Click(EDIT_CONTACT_DETAILS_BUTTON)
    ContractDetailEditContactModal opensContactDetailsModal();

    @Click(BUTTON_ASSIGN_PROCESSING_TEAM)
    ContractAssignToBankModal clickAssignProcessingTeam();

    @Wait(value = BUTTON_VALUATE, waitSecondsForElement = 10)
    @Click(BUTTON_VALUATE)
    ValuationPage clickValuateProperty();

    @Click(value = BUTTON_CHECKLIST, andWait = @Wait(value = CHECKLIST_LOADER, until = Until.GONE))
    ContractDetailPage clickChecklist();

    @Click(value = CHECKLIST_DOC, isStringDynamicXpath = true)
    ContractDetailPage clickChecklistDoc(String doc);

    @Click(CHECKLIST_DOC_UPLOAD_BUTTON)
    ContractChecklistDocumentDateModal clickChecklistDocUpload();

    @FileUpload(CHECKLIST_DOC_FILE_UPLOAD)
    ContractDetailPage checklistUploadFile(String filePath);

    @Wait(value = CHECKLIST_DOC_UPLOAD_LOADER, until = Until.GONE)
    ContractDetailPage waitChecklistUpload();

    @Wait(value = CHECKLIST_LOADER, until = Until.GONE)
    ContractDetailPage waitChecklist();

    @CheckElementPresent(CHECKLIST_DOC_UPLOADED)
    ContractDetailPage checkChecklistDocUploaded();
}