from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
import sys

from playwright.sync_api import sync_playwright

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

from e2e.pages.product_solution_admin_page import ProductSolutionAdminPage


@dataclass(frozen=True)
class Settings:
    admin_url: str = "https://test-saas-adminui.lianlianwz.com/pages/home/index"
    admin_username: str = "wangss"
    admin_password: str = "123456"


def main() -> None:
    settings = Settings()
    timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(headless=False, slow_mo=100)
        page = browser.new_page(viewport={"width": 1920, "height": 1080})
        admin = ProductSolutionAdminPage(page, settings.admin_url)
        admin.login(settings.admin_username, settings.admin_password)

        product_code, product_name = admin.open_any_existing_version_product_view()
        admin.open_feature_compare_config()
        admin.add_feature_compare_switch_and_text_rows(
            version_name="",
            switch_item_name=f"探测开关项_{timestamp}",
            text_item_name=f"探测文本项_{timestamp}",
            text_item_value=f"探测文本值_{timestamp}",
        )
        admin.save_feature_compare_config()
        print(f"feature compare saved: {product_code}/{product_name}")
        browser.close()


if __name__ == "__main__":
    main()
