using System;
using System.Threading.Tasks;
using NetWorkMessage;

namespace ActorCore
{
    public readonly struct MessageSenderStruct
    {
        /// <summary>
        /// 目的地
        /// </summary>
        public ActorId ActorId { get; }

        /// <summary>
        /// 请求类型
        /// </summary>
        public Type RequestType { get; }

        private readonly TaskCompletionSource<IResponse> tcs;
        

        public MessageSenderStruct(ActorId actorId, Type requestType)
        {
            this.ActorId = actorId;
            this.RequestType = requestType;

            this.tcs = new TaskCompletionSource<IResponse>();
        }

        public void SetResult(IResponse response)
        {
            this.tcs.SetResult(response);
        }

        public void SetException(Exception exception)
        {
            this.tcs.SetException(exception);
        }

        public async Task<IResponse> Wait()
        {
            return await this.tcs.Task;
        }
    }
}