using Back.Common;
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;
using Shared.DTOs;
using Shared.DTOs.Serch;

namespace Back.Services
{
    public class Servstuff
    {
        private readonly IAsyncRepository<stuff> _repostuff;
        public Servstuff(IAsyncRepository<stuff> repostuff)
        {
            _repostuff=repostuff;
        }
        public async Task<PagingDto<stuffDto>> Getstuff(GridDataProviderRequestDto value)
        {
            //Contains
            var request = _repostuff.GetAll();
            foreach (var item in value.Filters)
            {
                switch (item.PropertyName)
                {
                    case "ID":
                        request = request.Where(w=>w.CID.Contains( item.Value) || w.CID == item.Value);
                        break;
                    case "DescriptionOfID":
                        request = request.Where(w => w.DescriptionOfID.Contains(item.Value) || w.DescriptionOfID == item.Value);
                        break;
                    default:
                        break;
                }
            }
            return await request.Select(s=>new stuffDto
            {
                DescriptionOfID=s.DescriptionOfID,
                ID=string.IsNullOrEmpty(s.CID) ? 0 :Convert.ToUInt64(s.CID),
                TaxableOrFree=s.TaxableOrFree,
                Type=s.sType,
                Vat= string.IsNullOrEmpty(s.Vat) ? 0 :Convert.ToInt32(s.Vat),
               // VatCustomPurposes = string.IsNullOrEmpty(s.VatCustomPurposes) ? 0 : Convert.ToInt32(s.VatCustomPurposes)
                
            }).Paging(value.PageNumber,value.PageSize);
        }
    }
}
