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 ConfigUnitsRepository : MongoRepository<ConfigUnits>, IConfigUnitsRepository
{
    private readonly ApiSettings _apiSettings;

    public ConfigUnitsRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database) : base(database)
    {
        if (apiSettings == null) throw new ArgumentNullException(nameof(apiSettings));
        _apiSettings = apiSettings.Value;
    } //For testing

    


    public override string GetCollectionName()
    {
        return _apiSettings.ConfigUnits ?? "config_units";
    }

    public async Task<ConfigUnits?> FindById(string id)
    {
        var resutl = await Collection.FindAsync(Builders<ConfigUnits>.Filter.Eq(x => x.Id, id));
        return resutl.FirstOrDefault();
    }
}