package cz.moneta.test.regression.channels.branch.archive;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.Disabled;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import static cz.moneta.test.dsl.ufo.banka.pages.common.pages.OBR001_S001_PrintInstructionPage.ROOT_ID_KEY;
import static cz.moneta.test.harness.annotations.Environment.*;

@Disabled
@TestScenario(name = "Create new standing order")
public class CreateNewStandingOrder {

    @TestCase(name = "Create new standing order, edit it and cancel it", environments = {TST1, PPE, EDU})
    @JiraTestCase(id = "POB-T19530")
    public void createStandingOrder(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        String rcClient = harness.getConfig("branch.squad.rc.client");
        NonClient nonClient = harness.data().newNonClient()
                .withBirthNumber(rcClient);
        String receiverBankAccount = "115";
        String receiverBankCode = "0300";
        String firstAmount = "1";
        String finalAmount = "2";
        String receiverAccountName = "a";
        String firstPaymentDate = DateUtils.getNextWorkday().format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
        String lastPaymentDate = LocalDate.now().plusMonths(3L).format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRC(nonClient.birthNumber()))
                .checkProductActive("Běžný účet")
                .openCurrentAccountDetailPage()
                .openListOfStandingOrdersPage()
                .clickCreate()
                .fillReceiverAccountNumber(receiverBankAccount)
                .fillReceiverAccountBankCode(receiverBankCode)
                .fillReceiverAccountName(receiverAccountName)
                .fillFirstPaymentDate(firstPaymentDate)
                .fillLastPaymentDate(lastPaymentDate)
                .fillFirstAmount(firstAmount)
                .clickSave()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintInstructionPage()
                .storeRootId()
                .clickCenterButton()
                .onClientChargedPage()
                .clickOkToListTp()
                .checkStandingOrderStatusValid(harness.get(ROOT_ID_KEY))
                .clickOnStandingOrder(harness.get(ROOT_ID_KEY))
                .then(bankaTasks.payment().changeStandingOrderFromList(finalAmount))
                .then(bankaTasks.payment().clickSignedAndStoreEditedRootId())
                .checkStandingOrderAmount(harness.get(ROOT_ID_KEY), "2")
                .clickOnStandingOrder(harness.get(ROOT_ID_KEY))
                .then(bankaTasks.payment().deleteStandingOrderAndCheckStatusDeleted(String.valueOf(Integer.valueOf(harness.get(ROOT_ID_KEY)) + 1)));
    }
}
