package cz.moneta.test.dsl.hypos.pages.hypokalkulacka;

import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.hypos.HyposEndpoint;
import cz.moneta.test.harness.support.web.CustomAction;
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 org.openqa.selenium.TimeoutException;

import static cz.moneta.test.dsl.hypos.pages.hypokalkulacka.HypokalkulackaDocumentSignature.SAVE_SIGNATURE_BUTTON;

@Wait(value = SAVE_SIGNATURE_BUTTON, until = Until.VISIBLE)
public interface HypokalkulackaDocumentSignature extends HyposPageFlow<HypokalkulackaDocumentSignature>, StoreAccessor {
    String DOCUMENT_SUGNATURE_DIV = "//div[@id='document-signature']";
    String SIGNATURE_BYBANK_INPUT = DOCUMENT_SUGNATURE_DIV + "//input[@id='sign-date-bank']";
    String SIGNATURE_BYCLIENT_INPUT = DOCUMENT_SUGNATURE_DIV + "//input[@id='sign-date-client']";
    String SAVE_SIGNATURE_BUTTON = DOCUMENT_SUGNATURE_DIV + "//button[@id='butt-sign-doc']";

    @TypeInto(value = SIGNATURE_BYBANK_INPUT, andWait = @Wait(value = SAVE_SIGNATURE_BUTTON, until = Until.VISIBLE))
    HypokalkulackaDocumentSignature fillSignatureByBank(String signatureDate);

    @TypeInto(value = SIGNATURE_BYCLIENT_INPUT, andWait = @Wait(value = SAVE_SIGNATURE_BUTTON, until = Until.VISIBLE))
    HypokalkulackaDocumentSignature fillSignatureByClient(String signatureDate);

    @CustomAction
    default HypokalkulackaPage clickSaveDocumentSignatures() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.click(() -> SAVE_SIGNATURE_BUTTON);
        try {
            endpoint.acceptAlert(60); //ne vzdy se zobrazi
        } catch (TimeoutException e) {
        }
        return null;
    }
}
