"""Regression checks for SQL saved-state → Configurator refresh guidance."""

from __future__ import annotations

import sys
from pathlib import Path


CONNECTOR = Path(__file__).resolve().parents[2] / "plugins" / "1c" / "connector"
if str(CONNECTOR) not in sys.path:
    sys.path.insert(0, str(CONNECTOR))

import adapter_1c_server as adapter  # noqa: E402


EXTENSION_FILE = "fb26cf42-7609-11f1-828f-005056b0d483__77494708-43ea-4956-ac3c-199cfb035ad2.0"


def test_existing_extension_saved_object_reopens_object() -> None:
    result = adapter.saved_state_configurator_refresh_guidance(
        table="ConfigCASSave", file_name=EXTENSION_FILE, object_existed_in_saved_state=True
    )
    assert result["scope"] == "object"
    assert result["action"] == "close_reopen_object"


def test_new_extension_saved_object_reopens_extension() -> None:
    result = adapter.saved_state_configurator_refresh_guidance(
        table="ConfigCASSave", file_name=EXTENSION_FILE, object_existed_in_saved_state=False
    )
    assert result["scope"] == "extension"
    assert result["action"] == "close_reopen_extension"


def test_new_base_saved_object_reopens_configuration() -> None:
    result = adapter.saved_state_configurator_refresh_guidance(
        table="ConfigSave", file_name="77494708-43ea-4956-ac3c-199cfb035ad2.0", object_existed_in_saved_state=False
    )
    assert result["scope"] == "configuration"
    assert result["action"] == "close_reopen_configuration"
