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;

public class PoCMappingRepository : MongoRepository<PoCMapping>, IPoCMappingRepository
{
    private readonly ApiSettings _apiSettings;

    public PoCMappingRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database) : base(database)
    {
        _apiSettings = apiSettings.Value;
    } //For testing

    

    public override string GetCollectionName()
    {
        return _apiSettings.Mappings;
    }

    public async Task<PoCMapping?> FindByKey(string key)
    {
        var filterBuilder = Builders<PoCMapping>.Filter;
        var filter = filterBuilder.Eq(config => config.Id, key);

        var result = await Collection.FindAsync(filter);

        return await result.FirstOrDefaultAsync();
    }
}