"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createUser = exports.setupKeycloakUser = exports.adminPassword = exports.adminUser = exports.keycloakAdminCredentials = void 0;
const keycloakAdminCredentials = () => {
    return {
        username: 'admin',
        password: process.env.DISTRO_QA_E2E_TESTS_KEYCLOAK_PASSWORD,
    };
};
exports.keycloakAdminCredentials = keycloakAdminCredentials;
exports.adminUser = 'demo';
exports.adminPassword = process.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
const setupKeycloakUser = async (navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage) => {
    const testUsername = `test-user-${new Date().getTime()}-${Math.random()
        .toString(36)
        .substring(7)}`;
    const testPassword = 'test-password';
    await createKeycloakUser(navigationPage, keycloakLoginPage, keycloakAdminPage, testUsername, testPassword);
    await createIdentityUser(navigationPage, identityPage, testUsername);
    return { testUsername, testPassword };
};
exports.setupKeycloakUser = setupKeycloakUser;
const createUser = async (navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, username, password) => {
    await createKeycloakUser(navigationPage, keycloakLoginPage, keycloakAdminPage, username, password);
    await createIdentityUser(navigationPage, identityPage, username);
};
exports.createUser = createUser;
const createKeycloakUser = async (navigationPage, keycloakLoginPage, keycloakAdminPage, username, password) => {
    await navigationPage.goToKeycloak();
    await keycloakLoginPage.toBeVisible();
    await keycloakLoginPage.fillUsername((0, exports.keycloakAdminCredentials)().username);
    await keycloakLoginPage.fillPassword((0, exports.keycloakAdminCredentials)().password);
    await keycloakLoginPage.clickLogin();
    await keycloakAdminPage.toBeVisible();
    await keycloakAdminPage.switchToCamundaPlatform();
    await keycloakAdminPage.clickUsersTab();
    await keycloakAdminPage.clickAddUser();
    await keycloakAdminPage.fillUser(username);
    await keycloakAdminPage.saveUser();
    await keycloakAdminPage.fillPassword(password);
    await keycloakAdminPage.savePassword();
};
const createIdentityUser = async (navigationPage, identityPage, username) => {
    await navigationPage.goToIdentity();
    await identityPage.clickUsersLink();
    await identityPage.clickUser(username);
    await identityPage.clickAssignedRolesTab();
    await identityPage.clickAssignRolesButton();
    await identityPage.clickOperateCheckbox();
    await identityPage.clickTasklistCheckbox();
    await identityPage.clickOptimizeCheckbox();
    await identityPage.clickModelerCheckbox();
    await identityPage.clickConsoleCheckbox();
    await identityPage.clickZeebeCheckbox();
    await identityPage.clickIdentityCheckbox();
    await identityPage.clickModelerAdminCheckbox();
    await identityPage.clickAddButton();
};
