from __future__ import annotations

import pytest
from playwright.sync_api import Page

from e2e.pages.product_solution_admin_page import ProductSolutionAdminPage


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


@pytest.mark.e2e_standalone
def test_prodsol_flow_006_edit_product_version_app_config(page: Page, settings, bug_reporter) -> None:
    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, selected_app_version_name = admin.edit_product_version_app_config_and_finish(
        product_name_keywords=TARGET_PRODUCT_KEYWORDS,
    )
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=(
            "PRODSOL-FLOW-006 编辑产品版本选择启用且体验资源数量大于0的应用版本："
            f"{product_code}/{product_name}/{selected_app_version_name}"
        ),
    )

    admin.assert_product_version_edit_operation_log(product_code=product_code)
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=f"PRODSOL-FLOW-006 操作日志校验：{product_code}",
    )
