from __future__ import annotations
from dataclasses import dataclass
from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
    from flownet.api.actor_method_ref import ActorMethodRef


class ActorRef:
    def __init__(self, address: str, actor_id: str):
        self.address = address
        self.actor_id = actor_id
    
    
    # TODO: 这里需要区分一下本地actor，并且对于本地actor，直接通过队列调用actor方法并返回结果
    def __getattr__(self, name: str) -> 'ActorMethodRef':
        from flownet.api.actor_method_ref import ActorMethodRef
        return ActorMethodRef(address=self.address, actor_id=self.actor_id, method=name)

    def __reduce__(self):
        return (self.__class__, (self.address, self.actor_id))


class ContainerRef(ActorRef):
    def __init__(self, address: str):
        super().__init__(address=address, actor_id="__container__")
    
    def __getattr__(self, name):
        from flownet.api.actor_method_ref import ActorMethodRef
        print(f"[ContainerRef] Getting method {name} from container at {self.address}")
        return ActorMethodRef(address=self.address, actor_id="__container__", method=name)
