"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperateProcessInstancePage = void 0;
const test_1 = require("@playwright/test");
class OperateProcessInstancePage {
    page;
    diagram;
    completedIcon;
    diagramSpinner;
    activeIcon;
    incidentIcon;
    connectorResultVariableName;
    variablesList;
    messageVariable;
    constructor(page) {
        this.page = page;
        this.diagram = page.getByTestId('diagram');
        this.completedIcon = page
            .getByTestId('instance-header')
            .getByTestId('COMPLETED-icon');
        this.diagramSpinner = page.getByTestId('diagram-spinner');
        this.activeIcon = page
            .getByTestId('instance-header')
            .getByTestId('ACTIVE-icon');
        this.incidentIcon = page
            .getByTestId('instance-header')
            .getByTestId('INCIDENT-icon');
        this.connectorResultVariableName = (name) => page.getByTestId('variable-' + name);
        this.variablesList = page.getByTestId('variables-list');
        this.messageVariable = page.getByTestId('variable-message');
    }
    async reload() {
        await this.page.reload();
    }
    async connectorResultVariableValue(variableName) {
        return await this.page.getByTestId(variableName).locator('td').last();
    }
    async assertProcessCompleteStatusWithRetry(timeout = 60000, maxRetries = 10) {
        for (let attempt = 0; attempt < maxRetries; attempt++) {
            try {
                await this.page.reload();
                await (0, test_1.expect)(this.completedIcon).toBeVisible({
                    timeout: timeout,
                });
                return;
            }
            catch (error) {
                if (attempt < maxRetries - 1) {
                    console.warn(`Process complete status attempt ${attempt + 1} failed. Retrying...`);
                }
                else {
                    throw new Error(`Assertion failed after ${maxRetries} attempts`);
                }
            }
        }
    }
    async assertProcessVariableContainsText(variableName, text) {
        for (let attempt = 0; attempt < 3; attempt++) {
            try {
                await (0, test_1.expect)(this.page.getByTestId(`variable-${variableName}`)).toContainText(text, { timeout: 60000 });
                return;
            }
            catch (error) {
                if (attempt < 2) {
                    console.warn(`Attempt ${attempt + 1} failed. Reloading page...`);
                    await this.page.reload();
                }
                else {
                    throw error;
                }
            }
        }
    }
}
exports.OperateProcessInstancePage = OperateProcessInstancePage;
