"""
Exercise 1: __name__ == "__main__" and __all__ (single-file simulation)

Since this exercise must stay a single, self-contained file (no real
multi-file package to import from), it simulates two ideas from the
theory file using plain functions instead of an actual `import`:

STEP 1: Implement `is_main(name)` — a pure function that returns True
        if `name == "__main__"`, False otherwise. This models the check
        every script uses to distinguish "run directly" from "imported".

STEP 2: Implement `wildcard_import_names(all_list, defined_names)` —
        given an `__all__` list (or None if the module doesn't define
        one) and a list of every name defined at module level, return
        the list of names `from module import *` would actually bind:
          - if `all_list` is not None: return exactly `all_list`
            (regardless of underscores — __all__ is authoritative)
          - if `all_list` is None: return every name in `defined_names`
            that does NOT start with an underscore, preserving order
"""


def is_main(name):
    # TODO: return name == "__main__"
    pass


def wildcard_import_names(all_list, defined_names):
    # TODO: implement the two-branch logic described in STEP 2
    pass


# --- self-check: do not modify below this line ---
checks = []

checks.append(("is_main True for '__main__'", is_main("__main__"), True))
checks.append(("is_main False for a real module name", is_main("mymodule"), False))

checks.append(("wildcard_import_names uses __all__ when present, verbatim",
                wildcard_import_names(["public_fn"], ["public_fn", "_helper", "OTHER"]),
                ["public_fn"]))

checks.append(("wildcard_import_names filters underscore-prefixed names when __all__ is None",
                wildcard_import_names(None, ["public_fn", "_helper", "ANOTHER"]),
                ["public_fn", "ANOTHER"]))

checks.append(("wildcard_import_names with __all__=None and no private names returns everything",
                wildcard_import_names(None, ["a", "b", "c"]),
                ["a", "b", "c"]))

passed = 0
for label, actual, expected in checks:
    ok = actual == expected
    passed += ok
    print(f"{'PASS' if ok else 'FAIL'}: {label} (got {actual!r}, expected {expected!r})")

print("PASS" if passed == len(checks) else "FAIL")
