from __future__ import annotations

import os
import sys
from pathlib import Path

from dotenv import load_dotenv
from playwright.sync_api import sync_playwright

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from e2e.pages.tenant_auth_page import TenantAuthPage


load_dotenv()


def main() -> None:
    auth_key = os.getenv("E2E_AUTH_KEY", "209ac64d9e2b4a609d9a434e7b0c6898")
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False, slow_mo=120)
        context = browser.new_context(viewport={"width": 1440, "height": 900})
        page = context.new_page()
        auth_page = TenantAuthPage(page, os.getenv("TENANT_HOME_URL", "https://test-lianlianyun.lianlianwz.com/home"))
        auth_page.login_main_account(
            os.getenv("E2E_CERTIFIED_TENANT_PHONE", "19361091624"),
            os.getenv("E2E_CERTIFIED_TENANT_PASSWORD", "test123456"),
        )
        auth_page.verify_and_save_wanyouji_permissions(auth_key)
        print("verify ok")
        browser.close()


if __name__ == "__main__":
    main()
