using Fitness_core_BE.Interfaces; using Fitness_core_BE.Models; using Microsoft.EntityFrameworkCore; namespace Fitness_core_BE.Repos { public class CustomerNotificationRepository : ICustomerNotificationRepository { private readonly CentralDbContext _context; public CustomerNotificationRepository(CentralDbContext context) => _context = context; public async Task CreateAsync(CustomerNotification notification, CancellationToken ct = default) => await _context.CustomerNotifications.AddAsync(notification, ct); public async Task CreateManyAsync(IEnumerable notifications, CancellationToken ct = default) => await _context.CustomerNotifications.AddRangeAsync(notifications, ct); public async Task> GetByCustomerIdAsync(Guid customerId, CancellationToken ct = default) => await _context.CustomerNotifications .AsNoTracking() .Where(n => n.FKCustomerId == customerId) .OrderByDescending(n => n.CreatedAt) .ToListAsync(ct); public async Task GetByIdAsync(Guid customerNotificationId, Guid customerId, CancellationToken ct = default) => await _context.CustomerNotifications .FirstOrDefaultAsync(n => n.CustomerNotificationId == customerNotificationId && n.FKCustomerId == customerId, ct); public async Task GetCustomerPushTokenAsync(Guid customerId, CancellationToken ct = default) => await _context.Customer .AsNoTracking() .Where(c => c.CusId == customerId) .Select(c => c.PushTokenId) .FirstOrDefaultAsync(ct); public async Task> GetCustomerPushTokensAsync(IEnumerable customerIds, CancellationToken ct = default) { var ids = customerIds.Distinct().ToList(); if (ids.Count == 0) return new List(); return await _context.Customer .AsNoTracking() .Where(c => ids.Contains(c.CusId) && c.PushTokenId != null) .Select(c => c.PushTokenId!) .ToListAsync(ct); } } }