"""Simple smoke test to verify core InjectQ functionality."""

from injectq import inject, injectq, singleton, transient


def main():
    """Run basic smoke tests."""
    print("Running InjectQ smoke tests...")

    # Test 1: Basic container operations
    injectq[str] = "Hello, InjectQ!"
    assert injectq[str] == "Hello, InjectQ!"
    print("✓ Dict-like interface works")

    # Test 2: Class dependency injection
    class Database:
        def __init__(self, connection_string: str):
            self.connection_string = connection_string

    class UserService:
        def __init__(self, db: Database):
            self.db = db

        def get_info(self):
            return f"Connected to: {self.db.connection_string}"

    injectq.bind(Database, Database)
    injectq.bind(UserService, UserService)

    service = injectq.get(UserService)
    info = service.get_info()
    assert "Hello, InjectQ!" in info
    print("✓ Class dependency injection works")

    # Test 3: @inject decorator
    @inject
    def get_service_info(service: UserService) -> str:
        return service.get_info()

    result = get_service_info()  # type: ignore
    assert "Hello, InjectQ!" in result
    print("✓ @inject decorator works")

    # Test 4: @singleton decorator
    @singleton
    class SingletonService:
        def __init__(self, db: Database):
            self.db = db
            self.counter = 0

        def increment(self):
            self.counter += 1
            return self.counter

    s1 = injectq.get(SingletonService)
    s2 = injectq.get(SingletonService)
    assert s1 is s2
    assert s1.increment() == 1
    assert s2.increment() == 2  # Same instance
    print("✓ @singleton decorator works")

    # Test 5: @transient decorator
    @transient
    class TransientService:
        def __init__(self, db: Database):
            self.db = db
            self.id = id(self)

    t1 = injectq.get(TransientService)
    t2 = injectq.get(TransientService)
    assert t1 is not t2
    assert t1.id != t2.id
    print("✓ @transient decorator works")

    # Test 6: Factory functions
    def create_special_service() -> str:
        return "Special service created by factory"

    injectq.factories[str] = create_special_service

    # Note: This will override the previous str binding, showing factory precedence
    special = injectq.get(str)
    assert special == "Special service created by factory"
    print("✓ Factory functions work")

    print("\n🎉 All smoke tests passed! InjectQ is working correctly.")


if __name__ == "__main__":
    main()
