using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace AsbCloudInfrastructure.Services
{
#nullable enable
    public class LimitingParameterService : ILimitingParameterService
    {
        private readonly ILimitingParameterRepository limitingParameterRepository;
        private readonly IWellService wellService;

        public LimitingParameterService(ILimitingParameterRepository limitingParameterRepository,
            IWellService wellService)
        {
            this.limitingParameterRepository = limitingParameterRepository;
            this.wellService = wellService;
        }

        public async Task<IEnumerable<LimitingParameterDto>?> GetInfosAsync(LimitingParameterRequest request, CancellationToken token)
        {
            var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
            if (well?.IdTelemetry is null || well.Timezone is null)
                return null;

            return await limitingParameterRepository.GetInfosAsync(request, well, token);
        }
    }
#nullable disable
}