"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SM_8_8_1 = require("../../fixtures/SM-8.8");
const _setup_1 = require("../../test-setup.js");
const randomName_1 = require("../../utils/randomName");
const fileUpload_1 = require("../../utils/fileUpload");
let idpApplicationName;
let idpDocumentExtractionTemplateName;
const unstructuredTestCases = [
    {
        provider: 'AWS',
        model: 'Claude Sonnet 4',
        uploadFiles: ['idp/idp_sample_bank_statement.pdf'],
    },
];
const structuredTestCases = [
    {
        provider: 'AWS',
        model: '',
        uploadFiles: ['idp/structured_invoice_test.pdf'],
        extractionFiles: ['idp/structured_invoice_1.pdf'],
    },
]; /* For structured documents, the model is empty since it is not necessary */
if (process.env.IS_DS === 'true') {
    SM_8_8_1.test.describe('IDP User Flow Tests', () => {
        SM_8_8_1.test.afterEach(async ({ page }, testInfo) => {
            await (0, _setup_1.captureScreenshot)(page, testInfo);
            await (0, _setup_1.captureFailureVideo)(page, testInfo);
        });
        SM_8_8_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
            await navigationPage.goToModeler((testInfo.workerIndex + 1) * 1000);
        });
        SM_8_8_1.test.describe('Unstructured Extraction', () => {
            for (const params of unstructuredTestCases) {
                (0, SM_8_8_1.test)(`${params.provider} unstructured (${params.model}) - User creates an idp application with a document extraction template`, async ({ page, idpCreatePage, modelerHomePage, }) => {
                    SM_8_8_1.test.slow();
                    idpApplicationName = await (0, randomName_1.randomNameAgregator)(`${params.provider} unstructured` + ' - IDP_Application_Name');
                    idpDocumentExtractionTemplateName = await (0, randomName_1.randomNameAgregator)(`${params.provider} unstructured` +
                        ' - IDP_Extraction_Template_Name');
                    await SM_8_8_1.test.step('Navigate to Cross Component Test Project', async () => {
                        await modelerHomePage.clickCrossComponentProjectFolder();
                    });
                    await SM_8_8_1.test.step('Add an IDP application to the project', async () => {
                        await modelerHomePage.clickDiagramTypeDropdown();
                        await modelerHomePage.clickIdpApplicationTemplateOption();
                    });
                    await SM_8_8_1.test.step('Creates a document extraction template', async () => {
                        await modelerHomePage.enterIdpApplicationName(idpApplicationName);
                        await modelerHomePage.clickCreateIdpApplicationButton();
                        await idpCreatePage.clickCreateIdpTemplateButton();
                        await idpCreatePage.fillIdpExtractionTemplateName(`${idpDocumentExtractionTemplateName}`);
                        await idpCreatePage.fillIdpDescriptionField(`${idpDocumentExtractionTemplateName} description`);
                        await idpCreatePage.selectProvider(params.provider);
                        await idpCreatePage.clickCreateIdpExtractionTemplateButton();
                    });
                    await SM_8_8_1.test.step('Upload a file for extraction', async () => {
                        await idpCreatePage.clickUnstructuredUploadFilesButton();
                        await (0, fileUpload_1.uploadFile)(page, params.uploadFiles);
                        await idpCreatePage.clickExtractButton();
                    });
                    await SM_8_8_1.test.step('Add a field for extraction and extract the data', async () => {
                        await idpCreatePage.fillExtractFieldName('bank_account_number');
                        await idpCreatePage.fillPromptField();
                        await idpCreatePage.clickAddExtractionFieldButton();
                        await idpCreatePage.selectExtractionModelOption(params.model);
                        await idpCreatePage.clickExtractDocumentButton();
                    });
                    await SM_8_8_1.test.step('Save extracted data as a test case', async () => {
                        await idpCreatePage.clickSaveAsTestCaseButton();
                        await idpCreatePage.clickCloseToastNotification();
                    });
                    await SM_8_8_1.test.step('Validate extraction', async () => {
                        await idpCreatePage.clickValidateExtractionTab();
                        await idpCreatePage.clickExpandAllRowsButton();
                        await idpCreatePage.assertPassTestCaseResultsRow();
                    });
                    await SM_8_8_1.test.step('Publish the IDP application to project', async () => {
                        await idpCreatePage.clickPublishButton();
                        await idpCreatePage.clickPublishToProjectOption();
                        await idpCreatePage.fillVersionFieldName(idpApplicationName);
                        await idpCreatePage.fillVersionFieldDescription(idpApplicationName);
                        await idpCreatePage.clickPublishButtonModal();
                        await idpCreatePage.assertIdpSuccessPublishNotification();
                    });
                });
            }
        });
        SM_8_8_1.test.describe('Structured Extraction', () => {
            for (const params of structuredTestCases) {
                (0, SM_8_8_1.test)(`${params.provider} structured - User creates an idp application with a document extraction template`, async ({ page, idpCreatePage, modelerHomePage, }) => {
                    SM_8_8_1.test.slow();
                    idpApplicationName = await (0, randomName_1.randomNameAgregator)(`${params.provider} structured` + ' - IDP_Application_Name');
                    idpDocumentExtractionTemplateName = await (0, randomName_1.randomNameAgregator)(`${params.provider} structured` + ' - IDP_Extraction_Template_Name');
                    await SM_8_8_1.test.step('Navigate to Cross Component Test Project', async () => {
                        await modelerHomePage.clickCrossComponentProjectFolder();
                    });
                    await SM_8_8_1.test.step('Add an IDP application to the project', async () => {
                        await modelerHomePage.clickDiagramTypeDropdown();
                        await modelerHomePage.clickIdpApplicationTemplateOption();
                    });
                    await SM_8_8_1.test.step('Creates a document extraction template', async () => {
                        await modelerHomePage.enterIdpApplicationName(idpApplicationName);
                        await modelerHomePage.clickCreateIdpApplicationButton();
                        await idpCreatePage.clickCreateIdpTemplateButton();
                        await idpCreatePage.selectStructuredDataExtractionMethod();
                        await idpCreatePage.fillIdpExtractionTemplateName(`${idpDocumentExtractionTemplateName}`);
                        await idpCreatePage.fillIdpDescriptionField(`${idpDocumentExtractionTemplateName} - description`);
                        await idpCreatePage.selectProvider(params.provider);
                        await idpCreatePage.clickCreateIdpExtractionTemplateButton();
                    });
                    await SM_8_8_1.test.step('Upload a file for extraction', async () => {
                        await idpCreatePage.clickStructuredUploadFilesButton();
                        await (0, fileUpload_1.uploadFile)(page, params.uploadFiles);
                    });
                    await SM_8_8_1.test.step('Select all the fields extracted rows', async () => {
                        await idpCreatePage.selectAllExtractionFields();
                    });
                    await SM_8_8_1.test.step('Switch to the tables tab', async () => {
                        await idpCreatePage.clickTablesTab();
                    });
                    await SM_8_8_1.test.step('Select all the extracted tables', async () => {
                        await idpCreatePage.selectAllExtractedTables();
                    });
                    await SM_8_8_1.test.step('Confirm selection of fields and tables', async () => {
                        await idpCreatePage.assertFieldsAndTablesSelection();
                    });
                    await SM_8_8_1.test.step('Click on the Test Template tab', async () => {
                        await idpCreatePage.clickTestTemplateTab();
                    });
                    await SM_8_8_1.test.step('Upload multiple files for testing the extraction', async () => {
                        await idpCreatePage.clickStructuredUploadFilesButton();
                        await (0, fileUpload_1.uploadFile)(page, params.extractionFiles);
                        await idpCreatePage.assertMultipleFilesUploaded();
                        await idpCreatePage.clickTestExtractionTemplateButton();
                    });
                    await SM_8_8_1.test.step('Test Summary Results and Details Results sections are visible ', async () => {
                        await idpCreatePage.extractionResultsAreVisible();
                    });
                    await SM_8_8_1.test.step('Publish the IDP application to project', async () => {
                        await idpCreatePage.clickPublishTemplateButton();
                        await idpCreatePage.clickPublishToProjectOption();
                        await idpCreatePage.fillVersionFieldName(idpApplicationName);
                        await idpCreatePage.fillVersionFieldDescription(idpApplicationName);
                        await idpCreatePage.clickPublishTemplateToProjectButton();
                        await idpCreatePage.assertStructuredTemplateSuccessNotification();
                    });
                });
            }
        });
    });
}
