using Dapper;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Channel;
using XYY.Model.Standard.Order;

namespace XYY.Data.Standard.Channel
{
    public interface ILogistics_BoxRepository : IBaseRepository<Logistics_Box>
    {
        Task<IEnumerable<OrderConfimRequest>> GetBoxOrderConfirmItems(List<int> boxIds);
    }

    public class Logistics_BoxRepository : BaseRepository<Logistics_Box>, ILogistics_BoxRepository
    {
        public Logistics_BoxRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {

        }

        public Task<IEnumerable<OrderConfimRequest>> GetBoxOrderConfirmItems(List<int> boxIds)
        {
            string sql = @"select o.TrackingNumber as OrderNo,o.OPWeight,o.ChannelId,o.ServicesOrderNo,o.TrackingNumber,bd.Id as BoxDetailId,c.ServiceCode
from Logistics_Box b 
inner join Logistics_BoxDetail bd on b.id=bd.BoxId
inner join Order_Order o on o.id=bd.OrderId
inner join Logistics_Channel c on c.id=o.ChannelId
where b.id in @BoxIds and (bd.IsConfim is null or bd.IsConfim=0)";

            return base._unitOfWork.Connection.QueryAsync<OrderConfimRequest>(sql, new { BoxIds = boxIds }, base._unitOfWork.Transaction);
        }
    }
}

