package cz.moneta.test.regression.ufoframework;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.fon.UploadUtil;
import cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks;
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.regression.commercial.smallbusiness.digital.TearDown;
import org.junit.jupiter.api.AfterEach;

import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.ICO_KEY;
import static cz.moneta.test.harness.annotations.Environment.DEV;
import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "File Upload")
public class FileUpload {

    @TestCase(name = "File Upload", environments = {TST1, PPE, DEV})
    @JiraTestCase(id = "UFO-T516")
    public void fileUpload(Harness harness) {

        String clientIco = "48155497";
        harness.store(ICO_KEY, clientIco);
        String registrationNumber = harness.getConfig("commercial.cb.registration-number");
        String documentTitle = "test";
        String filePath = UploadUtil.getResourcePath("regression/ufo/cb/TEST_FILE_UPLOAD.pdf");

        CommercialTasks commercialTasks = harness.tasks().ufo().cb();
        harness.withUfo()
                .openLoginPage()
                .then(commercialTasks.loginAsCbBanker())
                .then(commercialTasks.searchClient(clientIco))
                .clickDocuments()
                .clickNewDocumentButton()
                .clickDocumentSentAsNormalLetter()
                .selectAccountNumberByRegistrationNumber(registrationNumber)
                .selectDocumentType("Ostatní")
                .saveDocument()
                .typeDocumentName(documentTitle)
                .uploadDocument(filePath)
                .clickSaveButton()
                .checkFirstDocumentName(documentTitle);
    }

    @AfterEach
    protected void tearDown(Harness harness) {
        TearDown.storeIcoFullNameCifSessionId(harness);
    }
}
