"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptimizeDashboardPage = void 0;
const test_1 = require("@playwright/test");
class OptimizeDashboardPage {
    page;
    filterTable;
    constructor(page) {
        this.page = page;
        this.filterTable = page.getByPlaceholder('Filter table');
    }
    async clickFilterTable() {
        await this.filterTable.click({ timeout: 120000 });
    }
    async fillFilterTable(processName) {
        await this.filterTable.fill(processName, { timeout: 60000 });
        await this.filterTable.press('Enter');
    }
    async processLinkAssertion(processName, maxRetries, retryDelay = 60000) {
        for (let attempt = 0; attempt < maxRetries; attempt++) {
            try {
                await this.page.reload();
                await this.clickFilterTable();
                await this.fillFilterTable(processName);
                await (0, test_1.expect)(this.page.getByRole('link', { name: processName })).toBeVisible({ timeout: 70000 });
                return;
            }
            catch (error) {
                if (attempt < maxRetries - 1) {
                    console.warn(`Attempt ${attempt + 1} failed for asserting process link in Optimize. Retrying...`);
                    await new Promise((resolve) => setTimeout(resolve, retryDelay));
                }
                else {
                    throw new Error(`Process link in Optimize assertion failed after ${maxRetries} attempts`);
                }
            }
        }
    }
    async processOwnerNameAssertion(processName, userEmail) {
        const maxRetries = 15;
        const retryDelay = 60000;
        const localPart = userEmail.split('@')[0];
        const uuid = localPart.replace('qa-user-', '');
        const result = !uuid ? 'QA Camunda' : `QA User ${uuid}`;
        for (let attempt = 0; attempt < maxRetries; attempt++) {
            try {
                await (0, test_1.expect)(this.page.getByRole('row', {
                    name: `${processName}\nProcess\n\t${result}`,
                })).toBeVisible({ timeout: 90000 });
                return;
            }
            catch (error) {
                if (attempt < maxRetries - 1) {
                    console.warn(`Attempt ${attempt + 1} failed for asserting owner name ${result} assertion for ${processName} in Optimize.. Retrying...`);
                    await this.page.reload();
                    await new Promise((resolve) => setTimeout(resolve, retryDelay));
                }
                else {
                    throw new Error(`Owner name ${result} assertion for ${processName} failed after ${maxRetries} attempts`);
                }
            }
        }
    }
}
exports.OptimizeDashboardPage = OptimizeDashboardPage;
