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

namespace XYY.Data.Standard.Order
{
    public interface ICustomerMaintenanceMsgRepository : IBaseRepository<Customer_Maintenance_Msg>
    {
        Task AddMsg(Customer_Maintenance_Msg msg);

        Task SetHandle(Customer_Maintenance_Msg msg);

        Task<PageResult<Customer_Maintenance_Msg>> GetPageResult(QueryModel queryModel);
    }
    public class CustomerMaintenanceMsgRepository : BaseRepository<Customer_Maintenance_Msg>, ICustomerMaintenanceMsgRepository
    {
        public CustomerMaintenanceMsgRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }

        public async Task AddMsg(Customer_Maintenance_Msg msg)
        {
            await _unitOfWork.InsertAsync(msg);
        }

        public async Task<PageResult<Customer_Maintenance_Msg>> GetPageResult(QueryModel queryModel)
        {
            return await _unitOfWork.GetPagingList2Async<Customer_Maintenance_Msg>(queryModel);
        }

        public async Task SetHandle(Customer_Maintenance_Msg msg)
        {
            await _unitOfWork.UpdateByConditionAsync<Customer_Maintenance_Msg, bool>(x => x.Id == msg.Id, new
            {
                IsHandle = true,
                HandleTime = DateTime.Now
            });
        }
    }
}
