using System.Threading.Tasks;
using MDL.Models;
using DAL.Interfaces;
using DB.Database;

namespace DAL.Repositories
{
    /// <summary>
    /// 收货扫描记录的数据访问实现类
    /// </summary>
    public class ArrivalScanRecordRepository : IArrivalScanRecordRepository
    {
        private readonly ISqlSugarProvider _provider;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="provider">SqlSugar数据库提供程序</param>
        public ArrivalScanRecordRepository(ISqlSugarProvider provider)
        {
            _provider = provider;
        }

        /// <summary>
        /// 插入一条收货扫描记录
        /// </summary>
        /// <param name="entity">扫描记录实体</param>
        /// <returns>插入的记录ID</returns>
        public async Task<int> InsertAsync(ArrivalScanRecordEntity entity)
        {
            var db = _provider.GetClient();

            entity.CreatedAt = DateTime.UtcNow;
            entity.UpdatedAt = DateTime.UtcNow;

            return await db.Insertable(entity).ExecuteReturnIdentityAsync();
        }
    }
}
