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_008_publish_online_offline_online(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 = admin.publish_online_offline_online_and_read_back(
        product_name_keywords=TARGET_PRODUCT_KEYWORDS,
    )
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=f"PRODSOL-FLOW-008 产品发布上架下架再上架回读：{product_code}/{product_name}",
    )

    admin.assert_product_publish_online_offline_operation_logs(product_code=product_code)
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=f"PRODSOL-FLOW-008 操作日志校验：发布/上架x2/下架产品，{product_code}",
    )
