using Edge.Core.Domain.FccOrderInfo.Input;
using Edge.Core.Domain.FccOrderInfo.Output;
using FccLite.Web.Repositories.FccOrderInfo;
using FccLite.Web.Repositories.FccStationInfo;

namespace FccLite.Web.Services.FccOrderInfo
{
    public class OrderInfoService : IOrderInfoService
    {
        private readonly IOrderInfoReposity _orderInfoReposity;
        private readonly IStationRepository _stationRepository;
        public OrderInfoService(IOrderInfoReposity orderInfoReposity,IStationRepository stationRepository) 
        {
            _orderInfoReposity = orderInfoReposity;
            _stationRepository = stationRepository;
        }


        public async Task<OrderInfoOutput> GetPage(OrderInfoPageInput orderInfoPageInput)
        {
            Edge.Core.Domain.FccStationInfo.FccStationInfo? fccStationInfo = await _stationRepository.GetFirstStation();
            IEnumerable<Edge.Core.Domain.FccOrderInfo.FccOrderInfo> enumerable = await _orderInfoReposity.GetPage(orderInfoPageInput);
            List<OrderInfo> orderInfos = enumerable.Select(order => new OrderInfo(order,fccStationInfo?.Name ?? "","")).ToList();
            return new OrderInfoOutput()
            {
                Total = orderInfos.Count,
                List = orderInfos
            };
        }
    }
}
