using adas_core.Application.Repositories.Interfaces;
using adas_core.Domain.Models.AppSettings;
using adas_core.Domain.Models.MongoModels;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
namespace adas_core.Infrastructure.Repositories;
///
/// Provides a MongoDB-backed repository implementation for PoCMapping entities.
///
public class PoCMappingRepository : MongoRepository, IPoCMappingRepository
{
private readonly ApiSettings _apiSettings;
public PoCMappingRepository(IOptions apiSettings, IMongoDatabase database) : base(database)
{
_apiSettings = apiSettings.Value;
} //For testing
///
/// Retrieves the name of the mappings collection from the API settings configuration.
///
/// The mappings collection name as configured in _apiSettings.
public override string GetCollectionName()
{
return _apiSettings.Mappings;
}
///
/// Asynchronously retrieves a from the underlying MongoDB collection by matching its against the supplied key, returning null when no matching document is found.
///
/// The unique identifier (Id) of the to look up.
/// A Task TResult containing the matching PoCMapping, or null if no document with the specified key exists in the collection.
public async Task FindByKey(string key)
{
var filterBuilder = Builders.Filter;
var filter = filterBuilder.Eq(config => config.Id, key);
var result = await Collection.FindAsync(filter);
return await result.FirstOrDefaultAsync();
}
}