using Microsoft.EntityFrameworkCore; using SPMS.Domain.Entities; using SPMS.Domain.Enums; using SPMS.Domain.Interfaces; namespace SPMS.Infrastructure.Persistence.Repositories; public class ServiceRepository : Repository, IServiceRepository { public ServiceRepository(AppDbContext context) : base(context) { } public async Task GetByServiceCodeAsync(string serviceCode) => await _dbSet.FirstOrDefaultAsync(s => s.ServiceCode == serviceCode); public async Task GetByApiKeyAsync(string apiKey) => await _dbSet.FirstOrDefaultAsync(s => s.ApiKey == apiKey); public async Task GetByIdWithIpsAsync(long id) => await _dbSet .Include(s => s.ServiceIps) .FirstOrDefaultAsync(s => s.Id == id); public async Task GetByServiceCodeWithIpsAsync(string serviceCode) => await _dbSet .Include(s => s.ServiceIps) .FirstOrDefaultAsync(s => s.ServiceCode == serviceCode); public async Task> GetByStatusAsync(ServiceStatus status) => await _dbSet.Where(s => s.Status == status).ToListAsync(); public async Task ServiceNameExistsAsync(string serviceName) => await _dbSet.AnyAsync(s => s.ServiceName == serviceName); public async Task ServiceCodeExistsAsync(string serviceCode) => await _dbSet.AnyAsync(s => s.ServiceCode == serviceCode); // ServiceIp methods public async Task GetServiceIpByIdAsync(long ipId) => await _context.Set().FirstOrDefaultAsync(ip => ip.Id == ipId); public async Task ServiceIpExistsAsync(long serviceId, string ipAddress) => await _context.Set() .AnyAsync(ip => ip.ServiceId == serviceId && ip.IpAddress == ipAddress); public async Task AddServiceIpAsync(ServiceIp serviceIp) => await _context.Set().AddAsync(serviceIp); public void DeleteServiceIp(ServiceIp serviceIp) => _context.Set().Remove(serviceIp); }