public async Task <IActionResult> GetOffersByFilter([FromBody] OffersFilterDTO filters)
        {
            var result = await _offersService.GetOffersByCategoryAsync(RequestLang, HostAddress, filters);

            return(Ok(result));
        }
        public async Task <List <OfferItemDTO> > GetOffersByCategoryAsync(Lang lang, string hostAddress, OffersFilterDTO filters)
        {
            IQueryable <Offer> query = _dbContext.Set <Offer>().Include(x => x.ShiftCenterService).ThenInclude(x => x.ShiftCenter);

            query = query.Where(x => x.Status == OfferStatus.APPROVED);

            query = query.Where(x => DateTime.Now >= x.StartAt && DateTime.Now <= x.ExpiredAt);

            query = query.Where(x => x.Type != OfferType.FREE_APPOINTMENTS || x.RemainedCount > 0);

            if (filters.CityId != null)
            {
                query = query.Where(x => x.ShiftCenterService.ShiftCenter.CityId == filters.CityId);
            }

            if (filters.ServiceCategoryId != null)
            {
                query = query.Where(x => x.ShiftCenterService.Service.ServiceCategoryId == filters.ServiceCategoryId);
            }

            if (filters.ServiceId != null)
            {
                query = query.Where(x => x.ShiftCenterService.HealthServiceId == filters.ServiceId);
            }

            if (filters.MinPrice != null)
            {
                query = query.Where(x => x.CurrentPrice != null && x.CurrentPrice >= filters.MinPrice);
            }

            if (filters.MaxPrice != null)
            {
                query = query.Where(x => x.CurrentPrice != null && x.CurrentPrice <= filters.MaxPrice);
            }

            if (filters.SortBy != null)
            {
                if (filters.SortDir == SortDir.ASC)
                {
                    if (filters.SortBy == OfferSort.Booking)
                    {
                        query = query.OrderBy(x => x.Appointments.Count);
                    }
                    if (filters.SortBy == OfferSort.Visits)
                    {
                        query = query.OrderBy(x => x.VisitsCount);
                    }
                    if (filters.SortBy == OfferSort.Price)
                    {
                        query = query.OrderBy(x => x.CurrentPrice);
                    }
                }
                else
                {
                    if (filters.SortBy == OfferSort.Booking)
                    {
                        query = query.OrderByDescending(x => x.Appointments.Count);
                    }
                    if (filters.SortBy == OfferSort.Visits)
                    {
                        query = query.OrderByDescending(x => x.VisitsCount);
                    }
                    if (filters.SortBy == OfferSort.Price)
                    {
                        query = query.OrderByDescending(x => x.CurrentPrice);
                    }
                }
            }
            else
            {
                query = query.OrderByDescending(x => x.CreatedAt);
            }

            var offers = await query.Select(x => new OfferItemDTO
            {
                Id = x.Id,
                ShiftCenterServiceId = x.ShiftCenterServiceId ?? 0,
                ServiceSupplyId      = x.ServiceSupplyId,
                CurrencyType         = x.CurrencyType == CurrencyType.USD ? "USD" : "IQD",
                OldPrice             = x.OldPrice,
                CurrentPrice         = x.CurrentPrice,
                DiscountPercentange  = x.DiscountPercentange,
                ShowDiscountBanner   = x.ShowDiscountBanner,
                Summary = lang == Lang.KU ? x.Summary_Ku : lang == Lang.AR ? x.Summary_Ar : x.Summary,
                Title   = lang == Lang.KU ? x.Title_Ku : lang == Lang.AR ? x.Title_Ar : x.Title,
                Photos  = new List <string>
                {
                    lang == Lang.KU ? $"{hostAddress}{x.Photo_Ku}" : lang == Lang.AR ?$"{hostAddress}{x.Photo_Ar}" : $"{hostAddress}{x.Photo}",
                },
                Photo = lang == Lang.KU ? $"{hostAddress}{x.Photo_Ku}" : lang == Lang.AR ? $"{hostAddress}{x.Photo_Ar}" : $"{hostAddress}{x.Photo}",
            }).ToListAsync();

            foreach (var item in offers)
            {
                var serviceSupply = await _dbContext.ServiceSupplies.FindAsync(item.ServiceSupplyId);

                if (serviceSupply == null)
                {
                    throw new AwroNoreException("Offer Doctor Not Found");
                }

                var x = serviceSupply;

                var shiftCenterService = x.ShiftCenter.PolyclinicHealthServices.FirstOrDefault(ss => ss.Id == item.ShiftCenterServiceId);

                item.ServiceSupply = new AN.Core.DTO.Doctors.DoctorListItemDTO
                {
                    Id                = x.Id,
                    FullName          = lang == Lang.KU ? x.Person.FullName_Ku : lang == Lang.AR ? x.Person.FullName_Ar : x.Person.FullName,
                    Avatar            = x.Person.RealAvatar,
                    ExpertiseCategory = x.DoctorExpertises.FirstOrDefault() != null ? lang == Lang.AR ? x.DoctorExpertises.FirstOrDefault().Expertise.ExpertiseCategory.Name_Ar : x.DoctorExpertises.FirstOrDefault().Expertise.ExpertiseCategory.Name_Ku : "",
                    Address           = lang == Lang.KU ? x.ShiftCenter.Address_Ku : x.ShiftCenter.Address_Ar,
                    HasEmptyTurn      = _doctorServiceManager.FindFirstEmptyTimePeriodFromNow(serviceSupply, shiftCenterService) != null,
                    AverageRating     = x.AverageRating != null ? (double)Math.Round((decimal)x.AverageRating, 2) : 5,
                    CenterServiceId   = item.ShiftCenterServiceId,
                    Service           = shiftCenterService == null ? "" : lang == Lang.KU ? shiftCenterService.Service.Name_Ku : lang == Lang.AR ? shiftCenterService.Service.Name_Ar : shiftCenterService.Service.Name,
                    ReservationType   = x.ReservationType,
                    CenterType        = x.ShiftCenter.Type
                };
            }

            return(offers);
        }