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 = ["自动化产品编辑_", "自动化产品_", "自动化产品"]


@pytest.mark.e2e_standalone
def test_prodsol_flow_007_version_status_copy_delete(page: Page, settings, bug_reporter) -> None:
    copied_version_name = f"自动化复制订阅版本_{datetime.now().strftime('%Y%m%d%H%M%S')}"

    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, copied_name = admin.product_version_status_copy_delete_and_finish(
        product_name_keywords=TARGET_PRODUCT_KEYWORDS,
        copied_version_name=copied_version_name,
    )
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=(
            "PRODSOL-FLOW-007 产品版本禁用启用复制后删除并回读："
            f"{product_code}/{product_name}/{copied_name}"
        ),
    )

    admin.assert_product_version_status_copy_delete_operation_logs(product_code=product_code)
    bug_reporter.record_if_errors(
        account=settings.admin_username,
        location=f"PRODSOL-FLOW-007 操作日志校验：禁用/启用/新建/删除产品版本，{product_code}",
    )
