from __future__ import annotations

import os

import pytest
from playwright.sync_api import Page

from e2e.tests.订单状态流转.上游发单.test_s_flow_007_create_order_with_dispatch import (
    test_s_flow_007_create_order_with_dispatch as _test_s_flow_007_create_order_with_dispatch,
)
from e2e.tests.订单状态流转.上游发单.test_s_flow_014_accept_upstream_order_from_hall import (
    test_s_flow_014_accept_upstream_order_from_hall as _test_s_flow_014_accept_upstream_order_from_hall,
)
from e2e.tests.订单状态流转.上游发单.test_s_flow_021_dispatch_accepted_order_to_player import (
    test_s_flow_021_dispatch_accepted_order_to_player as _test_s_flow_021_dispatch_accepted_order_to_player,
)
from e2e.tests.订单状态流转.上游发单.test_s_flow_026_player_accept_dispatched_order import (
    test_s_flow_026_player_accept_dispatched_order as _test_s_flow_026_player_accept_dispatched_order,
)
from e2e.tests.订单状态流转.下游发起撤销.test_s_flow_078_player_sub_order_revoke_terminal import (
    test_s_flow_078_player_sub_order_revoke_terminal as _test_s_flow_078_player_sub_order_revoke_terminal,
)
from e2e.tests.订单状态流转.处罚追缴.test_s_flow_072_open_penalty_recovery_from_terminal_sub_order import (
    test_s_flow_072_open_penalty_recovery_from_terminal_sub_order as _test_s_flow_072_open_penalty_recovery_from_terminal_sub_order,
)
from e2e.tests.订单状态流转.处罚追缴.test_s_flow_074_direct_penalty_player_amount import (
    test_s_flow_074_direct_penalty_player_amount as _test_s_flow_074_direct_penalty_player_amount,
)
from e2e.tests.订单状态流转.多子单履约.test_s_flow_032_continue_dispatch_after_cancelled_child import (
    test_s_flow_032_continue_dispatch_after_cancelled_child as _test_s_flow_032_continue_dispatch_after_cancelled_child,
)


@pytest.mark.flow_014
@pytest.mark.e2e_ledger
@pytest.mark.e2e_chain
def test_flow_014_upstream_revoke_rejected_penalty(page: Page, settings, bug_reporter) -> None:
    _test_s_flow_007_create_order_with_dispatch(page, settings, bug_reporter)
    _test_s_flow_014_accept_upstream_order_from_hall(page, settings, bug_reporter)
    _test_s_flow_021_dispatch_accepted_order_to_player(page, settings, bug_reporter)
    _test_s_flow_026_player_accept_dispatched_order(page, settings, bug_reporter)
    _test_s_flow_078_player_sub_order_revoke_terminal(page, settings, bug_reporter)
    previous_order_type = os.environ.get("E2E_S_FLOW_072_ORDER_TYPE")
    os.environ["E2E_S_FLOW_072_ORDER_TYPE"] = "处罚单"
    try:
        _test_s_flow_072_open_penalty_recovery_from_terminal_sub_order(page, settings, bug_reporter)
    finally:
        if previous_order_type is None:
            os.environ.pop("E2E_S_FLOW_072_ORDER_TYPE", None)
        else:
            os.environ["E2E_S_FLOW_072_ORDER_TYPE"] = previous_order_type
    _test_s_flow_074_direct_penalty_player_amount(page, settings, bug_reporter)
    _test_s_flow_032_continue_dispatch_after_cancelled_child(page, settings, bug_reporter)
