using System.Linq;
using Grpc.Core;
using System.Threading.Tasks;
using XYY.Service.Standard.TrackingService;

namespace XYY.gRpc.Tracking
{
    public class HandErrorLogService : HandErrorLog.HandErrorLogBase
    {
        ITrackingService _trackingService;

        public HandErrorLogService(ITrackingService trackingService)
        {
            _trackingService = trackingService;
        }

        public override async Task<BaseRes> PostData(HandErrorLogReq request, ServerCallContext context)
        {
            BaseRes br = new BaseRes();
            var res = await _trackingService.LogHandError(request.Logs.Select(x => new Data.Model.Standard.Tracking.Tracking_HandErrorLog
            {
                ErrorMessage = x.ErrorMessage,
                TrackingNumber = x.TrackingNumber,
                TargetTime = x.TargetTime.ToDateTime().ToLocalTime(),
                RequestMessage = x.RequestMessage,
                Source = x.Source
            }).ToList());
            br.Success = res.success;
            br.Message = res.message;
            return br;
        }
    }
}
