#nullable enable
using Baya.Application.Models.Common;
using Baya.Application.Models.Configuration;

namespace Baya.Application.Contracts.Configuration;

/// <summary>
/// Typed, cached accessor for runtime business parameters stored as rows in <c>platform_configs</c>.
/// Money-critical constants (commission %, VAT, deadlines, cancellation tiers) are read from here at
/// compute time — never hardcoded. Every write is audited in the same transaction.
/// </summary>
public interface IPlatformConfig
{
    /// <summary>Reads a config value and parses it to <typeparamref name="T"/> per the row's <c>data_type</c> (cached).</summary>
    ValueTask<T> GetConfig<T>(string key, CancellationToken cancellationToken = default);

    /// <summary>
    /// Updates an existing config row (and writes an audit entry, in one transaction) then evicts the cache.
    /// Returns <c>false</c> if the key does not exist. Changing a rate must never retroactively alter an
    /// already-computed amount — later phases snapshot the rate onto the priced row at compute time.
    /// </summary>
    ValueTask<bool> SetConfig(string key, string value, CancellationToken cancellationToken = default);

    ValueTask<PagedResult<PlatformConfigDto>> ListAsync(int page, int pageSize, CancellationToken cancellationToken = default);

    /// <summary>The audited change history for a single config key (from the append-only audit trail).</summary>
    ValueTask<PagedResult<ConfigChangeDto>> GetConfigChangeHistory(string key, int page, int pageSize, CancellationToken cancellationToken = default);
}
