using ZB.MOM.WW.ScadaBridge.Commons.Entities.InboundApi;

namespace ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;

public interface IInboundApiRepository
{
    // ApiKey persistence retired: inbound API keys live in the shared
    // ZB.MOM.WW.Auth.ApiKeys SQLite store, not the SQL Server configuration DB. The
    // former GetApiKeyByIdAsync / GetAllApiKeysAsync / GetApiKeyByValueAsync /
    // AddApiKeyAsync / UpdateApiKeyAsync / DeleteApiKeyAsync / GetApprovedKeysForMethodAsync
    // methods were removed with the SQL Server ApiKey entity.

    // ApiMethod
    /// <summary>Retrieves an API method by ID.</summary>
    /// <param name="id">The API method ID.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that resolves to the matching <see cref="ApiMethod"/>, or <c>null</c> if not found.</returns>
    Task<ApiMethod?> GetApiMethodByIdAsync(int id, CancellationToken cancellationToken = default);
    /// <summary>Retrieves all API methods.</summary>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that resolves to a read-only list of all <see cref="ApiMethod"/> entities.</returns>
    Task<IReadOnlyList<ApiMethod>> GetAllApiMethodsAsync(CancellationToken cancellationToken = default);
    /// <summary>Retrieves an API method by name.</summary>
    /// <param name="name">The API method name.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that resolves to the matching <see cref="ApiMethod"/>, or <c>null</c> if not found.</returns>
    Task<ApiMethod?> GetMethodByNameAsync(string name, CancellationToken cancellationToken = default);
    /// <summary>Adds a new API method.</summary>
    /// <param name="method">The API method to add.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task AddApiMethodAsync(ApiMethod method, CancellationToken cancellationToken = default);
    /// <summary>Updates an existing API method.</summary>
    /// <param name="method">The API method to update.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task UpdateApiMethodAsync(ApiMethod method, CancellationToken cancellationToken = default);
    /// <summary>Deletes an API method by ID.</summary>
    /// <param name="id">The API method ID.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task DeleteApiMethodAsync(int id, CancellationToken cancellationToken = default);

    /// <summary>Saves pending changes to the database.</summary>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that resolves to the number of state entries written to the database.</returns>
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
