"""Step definitions for resource_type_fs.feature."""

from __future__ import annotations

from pathlib import Path

from behave import given, then

_EXAMPLES_DIR = (
    Path(__file__).resolve().parent.parent.parent / "examples" / "resource-types"
)


# ── Given steps ──────────────────────────────────────────────


@given("the built-in fs-mount YAML file")
def step_builtin_fs_mount_yaml(context: object) -> None:
    context.builtin_yaml_path = (  # type: ignore[attr-defined]
        _EXAMPLES_DIR / "fs-mount.yaml"
    )


@given("the built-in fs-file YAML file")
def step_builtin_fs_file_yaml(context: object) -> None:
    context.builtin_yaml_path = (  # type: ignore[attr-defined]
        _EXAMPLES_DIR / "fs-file.yaml"
    )


# ── Then steps ───────────────────────────────────────────────


@then("the builtin schema user_addable should be true")
def step_builtin_user_addable_true(context: object) -> None:
    schema = context.builtin_schema  # type: ignore[attr-defined]
    assert schema.user_addable is True


@then("the builtin schema user_addable should be false")
def step_builtin_user_addable_false(context: object) -> None:
    schema = context.builtin_schema  # type: ignore[attr-defined]
    assert schema.user_addable is False


@then("the builtin schema should have empty child_types")
def step_builtin_empty_child_types(context: object) -> None:
    schema = context.builtin_schema  # type: ignore[attr-defined]
    assert len(schema.child_types) == 0


@then('the builtin auto_discovery should have rule for "{rtype}"')
def step_builtin_auto_discovery_rule(context: object, rtype: str) -> None:
    schema = context.builtin_schema  # type: ignore[attr-defined]
    assert schema.auto_discovery is not None
    rules = schema.auto_discovery.get("rules", [])
    types_found = [r.get("type") for r in rules]
    assert rtype in types_found, (
        f"Expected rule for '{rtype}' in auto_discovery, found: {types_found}"
    )
