package cz.moneta.test.regression.commercial.cb.archive;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.cb.landing.DMS424_S001_UploadFile;
import cz.moneta.test.dsl.util.data.client.NewClientCommercial;
import cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks;
import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;

import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@Disabled
@TestScenarioWithOrder(name = "Save documents to client")
public class SaveDocumentToClient {

    private String ico;
    private CommercialTasks tasks;

    @BeforeAll
    public void setUp(Harness harness) {
        tasks = harness.tasks().ufo().cb();
        NewClientCommercial newClientCommercial = tasks.createNewGlobalFopBe();
        ico = newClientCommercial.getClientData().ico();
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("ICO: %s <br>", ico));
    }

    private DMS424_S001_UploadFile accessSavingDocument(Harness harness) {
        String type = "Ostatní";
        return harness.withUfo()
                .openLoginPage()
                .then(tasks.loginAsCbBanker())
                .then(tasks.searchClient(ico))
                .clickDocuments()
                .clickNewDocumentButton()
                .selectDocumentType(type)
                .saveDocument();

    }

    @Order(1)
    @TestCase(name = "Save PDF document to client", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T358")
    public void savePdfDocument(Harness harness) {
        String doc_path = "regression/ufo/cb/Pdf.pdf";
        String name = doc_path.substring(doc_path.length() - 3).toUpperCase() + " " + java.time.LocalTime.now() + " " + java.time.LocalDate.now();
        accessSavingDocument(harness)
                .typeDocumentName(name)
                .uploadDocument(doc_path)
                .clickSaveButton()
                .checkDocumentName(name);
    }

    @Order(2)
    @TestCase(name = "Save DOC document to client", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T359")
    public void saveDocDocument(Harness harness) {
        String doc_path = "regression/ufo/cb/Doc.doc";
        String name = doc_path.substring(doc_path.length() - 3).toUpperCase() + " " + java.time.LocalTime.now() + " " + java.time.LocalDate.now();
        accessSavingDocument(harness)
                .typeDocumentName(name)
                .uploadDocument(doc_path)
                .clickSaveButton()
                .checkDocumentName(name);
    }

    @Order(3)
    @TestCase(name = "Save MSG document to client", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T360")
    public void saveMsgDocument(Harness harness) {
        String doc_path = "regression/ufo/cb/Msg.msg";
        String name = doc_path.substring(doc_path.length() - 3).toUpperCase() + " " + java.time.LocalTime.now() + " " + java.time.LocalDate.now();
        accessSavingDocument(harness)
                .typeDocumentName(name)
                .uploadDocument(doc_path)
                .clickSaveButton()
                .checkDocumentName(name);
    }

    @Order(4)
    @TestCase(name = "Save TIF document to client", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T361")
    public void saveTifDocument(Harness harness) {
        String doc_path = "regression/ufo/cb/Tiff.tif";
        String name = doc_path.substring(doc_path.length() - 3).toUpperCase() + " " + java.time.LocalTime.now() + " " + java.time.LocalDate.now();
        accessSavingDocument(harness)
                .typeDocumentName(name)
                .uploadDocument(doc_path)
                .clickSaveButton()
                .checkDocumentName(name);
    }

    @Order(5)
    @TestCase(name = "Save XLS document to client", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T362")
    public void saveXlsDocument(Harness harness) {
        String doc_path = "regression/ufo/cb/Xls.xls";
        String name = doc_path.substring(doc_path.length() - 3).toUpperCase() + " " + java.time.LocalTime.now() + " " + java.time.LocalDate.now();
        accessSavingDocument(harness)
                .typeDocumentName(name)
                .uploadDocument(doc_path)
                .clickSaveButton()
                .checkDocumentName(name);
    }

    @Order(6)
    @TestCase(name = "Save JPG document to client", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T363")
    public void saveJpgDocument(Harness harness) {
        String doc_path = "regression/ufo/cb/Jpg.jpg";
        String name = doc_path.substring(doc_path.length() - 3).toUpperCase() + " " + java.time.LocalTime.now() + " " + java.time.LocalDate.now();
        accessSavingDocument(harness)
                .typeDocumentName(name)
                .uploadDocument(doc_path)
                .clickSaveButton()
                .checkDocumentName(name);
    }
}
