using Meezi.Core.Enums;
using Meezi.Core.Platform;

namespace Meezi.Infrastructure.Services.Platform;

public interface IPlatformCatalogService
{
    Task<IReadOnlyList<PlanDefinitionDto>> GetPlansAsync(CancellationToken cancellationToken = default);
    Task<PlanDefinitionDto?> GetPlanAsync(PlanTier tier, CancellationToken cancellationToken = default);
    Task<PlanLimitsData> GetLimitsAsync(PlanTier tier, CancellationToken cancellationToken = default);
    Task<decimal> GetMonthlyPriceTomanAsync(PlanTier tier, CancellationToken cancellationToken = default);
    Task<bool> IsBillableOnlineAsync(PlanTier tier, CancellationToken cancellationToken = default);

    Task<IReadOnlyList<PlatformSettingDto>> GetSettingsAsync(CancellationToken cancellationToken = default);
    Task<string?> GetSettingAsync(string key, CancellationToken cancellationToken = default);

    Task<IReadOnlyList<PlatformFeatureDto>> GetFeaturesAsync(CancellationToken cancellationToken = default);
    Task<IReadOnlyDictionary<string, bool>> GetEffectiveFeaturesForCafeAsync(
        string cafeId,
        PlanTier planTier,
        CancellationToken cancellationToken = default);
    Task<bool> IsFeatureEnabledForCafeAsync(
        string cafeId,
        PlanTier planTier,
        string featureKey,
        CancellationToken cancellationToken = default);

    void InvalidateCache();
}

public record PlanDefinitionDto(
    PlanTier Tier,
    string DisplayNameFa,
    string? DisplayNameEn,
    decimal MonthlyPriceToman,
    bool IsBillableOnline,
    bool IsActive,
    int SortOrder,
    PlanLimitsData Limits,
    IReadOnlyList<string> FeatureKeys);

public record PlatformSettingDto(
    string Id,
    string Key,
    string Value,
    string Category,
    string? DescriptionFa,
    DateTime UpdatedAt);

public record PlatformFeatureDto(
    string Id,
    string Key,
    string DisplayNameFa,
    string? DisplayNameEn,
    string ModuleGroup,
    bool IsEnabledGlobally,
    DateTime UpdatedAt);
