import { Locator, Page, expect } from "@playwright/test";
import { WebAllLocators } from "../locator";

export class createRoleAndUser {
    readonly page: Page;
    readonly locators: WebAllLocators;

    constructor(page: Page) {
        this.page = page;
        this.locators = new WebAllLocators(page);
    }

    async sellerCreateRoleGoto() {
        await this.page.goto("seller/settings/roles");
    }

    async sellerCreateUserGoto() {
        await this.page.goto("seller/settings/users");
    }

    async sellerCreateaRole(
        permission_type: string,
        roleName: string,
        description: string
    ) {
        await this.locators.clickCreateRoleButton.click();
        await this.locators.permissionType.selectOption(permission_type);
        await this.locators.roleName.fill(roleName);
        await this.locators.roleDescription.fill(description);
        await this.locators.clickSaveRoleButton.click();
        await this.page.waitForTimeout(2000);
        await expect(this.locators.roleCreateSuccessToast).toBeVisible();
    }

    async sellerCreateUser(
        username: string,
        useremail: string,
        password: string,
        userrole: number,
        number: Number
    ) {
        await this.locators.clickCreateUserButton.click();
        await this.locators.userName.fill(username);
        await this.locators.userEmail.fill(useremail);
        await this.locators.userPhoneNumber.fill(number.toString());
        await this.locators.userPassword.fill(password);
        await this.locators.userConfirmPassword.fill(password);

        await this.locators.selectUserRole.selectOption({ index: userrole });
        await this.locators.userStatus.click();

        await this.locators.saveUserbutton.click();
        await this.page.waitForTimeout(2000);
        await expect(this.locators.createUserSuccessToast).toBeVisible();
    }
}
