using DataSharing.Share.Dtos.LuZhou;
using XF.Domain.Dependency;

namespace DataSharing.LuZhou.LuZhou110
{
    public class LZ110RegisterManager: ILZ110RegisterManager, IScopeDependency
    {
        private readonly LZ110Invoker _invoker;

        public LZ110RegisterManager(LZ110Invoker invoker)
        {
            _invoker = invoker;
        }

        private async Task<LZ110ApiResponse<LZ110BaseResponse>> RegisterAsync(CancellationToken cancellationToken)
        {
            return await _invoker.InvokeAsync<LZ110RegisterRequest, LZ110BaseResponse>(
                new(), cancellationToken);
        }

        private Task UnRegisterAsync(CancellationToken cancellationToken)
        {
            return _invoker.InvokeAsync<LZ110UnRegisterRequest, LZ110BaseResponse>(
                new(), cancellationToken);
        }

        public Task RefreshRegisterAsync(CancellationToken cancellationToken)
        {
            return Task.WhenAll(
                UnRegisterAsync(cancellationToken),
                RegisterAsync(cancellationToken)
            );
        }
    }
}
