from __future__ import annotations

import os

import pytest
from playwright.sync_api import Page

from e2e.pages.data_dictionary_page import DataDictionaryPage, DictionaryOption


DATA_CONFIG_BRANCHES = [
    (
        "DATA-CONFIG-001",
        DictionaryOption(
            dictionary_name=os.getenv("E2E_WORK_ORDER_PROBLEM_TYPE_DICT", "工单-问题类型"),
            option_name=os.getenv("E2E_WORK_ORDER_PROBLEM_TYPE_NAME", "E2E售后问题"),
        ),
    ),
    (
        "DATA-CONFIG-002",
        DictionaryOption(
            dictionary_name=os.getenv("E2E_WORK_ORDER_URGENCY_DICT", "工单-紧急程度"),
            option_name=os.getenv("E2E_WORK_ORDER_URGENCY_NAME", "E2E普通紧急"),
            resolve_minutes=os.getenv("E2E_WORK_ORDER_URGENCY_MINUTES", "240"),
        ),
    ),
    (
        "DATA-CONFIG-003",
        DictionaryOption(
            dictionary_name=os.getenv("E2E_WORK_ORDER_FOLLOW_TYPE_DICT", "工单-跟进类型"),
            option_name=os.getenv("E2E_WORK_ORDER_FOLLOW_TYPE_NAME", "E2E售后跟进"),
        ),
    ),
    (
        "DATA-CONFIG-004",
        DictionaryOption(
            dictionary_name=os.getenv("E2E_AFTERSALE_APPLY_TYPE_DICT", "售后-申请类型"),
            option_name=os.getenv("E2E_AFTERSALE_APPLY_TYPE_NAME", "E2E售后申请"),
        ),
    ),
    (
        "DATA-CONFIG-005",
        DictionaryOption(
            dictionary_name=os.getenv("E2E_APPEAL_TYPE_DICT", "申诉类型"),
            option_name=os.getenv("E2E_APPEAL_TYPE_NAME", "E2E售后申诉"),
        ),
    ),
    (
        "DATA-CONFIG-006",
        DictionaryOption(
            dictionary_name=os.getenv("E2E_PENALTY_TYPE_DICT", "处罚类型"),
            option_name=os.getenv("E2E_PENALTY_TYPE_NAME", "E2E售后处罚"),
        ),
    ),
]


@pytest.mark.e2e_standalone
@pytest.mark.data_config_001
@pytest.mark.data_config_002
@pytest.mark.data_config_003
@pytest.mark.data_config_004
@pytest.mark.data_config_005
@pytest.mark.data_config_006
def test_data_config_001_006_data_dictionary_options(
    page: Page,
    settings,
    bug_reporter,
) -> None:
    wanzhanggui_phone = os.getenv("E2E_ORDER_WANZHANGGUI_PHONE", settings.wanzhanggui_tenant_phone)
    wanzhanggui_password = os.getenv("E2E_ORDER_WANZHANGGUI_PASSWORD", settings.wanzhanggui_tenant_password)

    dictionary_page = DataDictionaryPage(page, settings.tenant_home_url, bug_reporter)
    dictionary_page.login_main_account(wanzhanggui_phone, wanzhanggui_password)
    bug_reporter.record_if_errors(account=wanzhanggui_phone, location="DATA-CONFIG-001~006 丸掌柜账号登录")
    dictionary_page.ensure_dictionary_options([option for _, option in DATA_CONFIG_BRANCHES])
    for case_id, option in DATA_CONFIG_BRANCHES:
        bug_reporter.record_if_errors(
            account=wanzhanggui_phone,
            location=f"{case_id} 商家管理-数据字典-{option.dictionary_name}配置",
        )
