using adas_core.Application.Exceptions;
using adas_core.Application.Repositories.Interfaces;
using adas_core.Application.Services.Interfaces;
using adas_core.Domain.Enums;
using adas_core.Domain.Models.MongoModels;
using MongoDB.Bson;

namespace adas_core.Application.Services;

/// <summary>
/// Provides an implementation of the IAlertValuesService interface for managing alert values
/// using a configuration observation repository.
/// </summary>
public class AlertValuesService(IConfigObservationRepository alertValueRepository) : IAlertValuesService
{
    /// <summary>
    /// Retrieves a <see cref="ConfigObservation"/> by its unique identifier from the alert value repository.
    /// Throws a <see cref="NotFoundException"/> when no matching resource is found.
    /// </summary>
    /// <param name="key">The unique identifier of the configuration observation to retrieve.</param>
    /// <returns>The matching <see cref="ConfigObservation"/> if found.</returns>
    /// <exception cref="NotFoundException">Thrown when no configuration observation exists for the specified <paramref name="key"/>.</exception>
    public async Task<ConfigObservation?> FindByKey(ObjectId key)
        {
            return await alertValueRepository.FindById(key) ??
                   throw new NotFoundException(HttpEnum.ErrorMessage.NotFoundResourceMissing);
        }
}