using Managing.Application.Abstractions.Services;
using Microsoft.Extensions.Logging;
using static Managing.Common.Enums;

namespace Managing.Application.Workers;

/// <summary>
/// Represents a worker that watches traders and performs actions based on trading activities.
/// Inherits from <see cref="BaseWorker{TWorker}"/> where TWorker is <see cref="TraderWatcher"/>.
/// </summary>
public class TraderWatcher : BaseWorker<TraderWatcher>
{
    private readonly ITradingService _tradingService;
    private static readonly WorkerType _workerType = WorkerType.TraderWatcher;

    /// <summary>
    /// Initializes a new instance of the <see cref="TraderWatcher"/> class.
    /// </summary>
    /// <param name="logger">The logger to be used by the worker.</param>
    /// <param name="tradingService">The trading service to monitor trading activities.</param>
    /// <param name="workerService">The worker service to manage worker lifecycle.</param>
    public TraderWatcher(
        ILogger<TraderWatcher> logger,
        IServiceProvider serviceProvider,
        ITradingService tradingService) : base(
        _workerType,
        logger,
        TimeSpan.FromSeconds(120),
        serviceProvider
        )
    {
        _tradingService = tradingService;
    }

    /// <summary>
    /// Executes the worker's task to watch traders. This method is called periodically based on the worker's configured interval.
    /// </summary>
    /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
    protected override async Task Run(CancellationToken cancellationToken)
    {
        await _tradingService.WatchTrader();
    }
} 