from __future__ import annotations

from datetime import datetime

import pytest
from playwright.sync_api import Page

from e2e.pages.product_solution_admin_page import ProductSolutionAdminPage


TARGET_PRODUCT_KEYWORDS = ["自动化产品编辑", "自动化产品a", "自动化产品"]


@pytest.mark.e2e_standalone
def test_prodsol_flow_009_create_product_menu(page: Page, settings, bug_reporter) -> None:
    timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
    menu_name = f"自动化产品菜单_{timestamp}"
    menu_code = f"auto_product_menu_{timestamp}"

    admin = ProductSolutionAdminPage(page, settings.admin_url)
    admin.login(settings.admin_username, settings.admin_password)
    bug_reporter.record_if_errors(account=settings.admin_username, location="SaaS Admin 登录")

    product_code, product_name, created_menu_code = admin.create_product_menu_and_read_back(
        product_name_keywords=TARGET_PRODUCT_KEYWORDS,
        menu_name=menu_name,
        menu_code=menu_code,
    )
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=f"PRODSOL-FLOW-009 配置菜单并创建产品菜单：{product_code}/{product_name}/{created_menu_code}",
    )
