// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FloraMultiPlatformFrontend.Presentation.Models.Charts;

namespace FloraMultiPlatformFrontend.Data.Repositories.Interfaces;

/// <summary>
/// Repository interface for accessing historical IO tag data from date-partitioned tables.
/// Historical IO data is stored in tables with the pattern: {serverName}_{machineCode}_IOStateData_TBM_{yyMMdd}
/// </summary>
public interface IIoHistoryTagDataRepository
{
    /// <summary>
    /// Gets historical IO tag data for a specific tag ID within a date range.
    /// Returns change-only data points (sparse data).
    /// </summary>
    /// <param name="tagId">The IO tag ID to retrieve</param>
    /// <param name="startDate">Start of the date range</param>
    /// <param name="endDate">End of the date range</param>
    /// <param name="machineCode">Machine code identifier</param>
    /// <param name="cancellationToken">Cancellation token</param>
    /// <returns>Collection of chart data points with timestamp and value (0.0 or 1.0 for boolean IO tags)</returns>
    Task<IEnumerable<ChartDataPoint>> GetIoTagHistoryAsync(
        int tagId,
        DateTime startDate,
        DateTime endDate,
        string machineCode,
        CancellationToken cancellationToken = default
    );

    /// <summary>
    /// Gets historical IO tag data for multiple tag IDs within a date range.
    /// Optimized for fetching multiple tags in a single query.
    /// </summary>
    /// <param name="tagIds">Collection of IO tag IDs to retrieve</param>
    /// <param name="startDate">Start of the date range</param>
    /// <param name="endDate">End of the date range</param>
    /// <param name="machineCode">Machine code identifier</param>
    /// <param name="cancellationToken">Cancellation token</param>
    /// <returns>Dictionary mapping tag ID to its collection of chart data points</returns>
    Task<IDictionary<int, IEnumerable<ChartDataPoint>>> GetMultipleIoTagsHistoryAsync(
        IEnumerable<int> tagIds,
        DateTime startDate,
        DateTime endDate,
        string machineCode,
        CancellationToken cancellationToken = default
    );
}
