using CMSMicroservice.Protobuf.Protos.Configuration;

namespace FrontOffice.Main.Utilities;

/// <summary>
/// سرویس تنظیمات باشگاه مشتریان
/// </summary>
public class ClubConfigurationService
{
    private readonly ConfigurationContract.ConfigurationContractClient _client;

    public ClubConfigurationService(ConfigurationContract.ConfigurationContractClient client)
    {
        _client = client;
    }

    /// <summary>
    /// دریافت تنظیمات باشگاه مشتریان
    /// </summary>
    public async Task<ClubConfigDto> GetClubConfigurationAsync()
    {
        var response = await _client.GetClubConfigurationAsync(new Google.Protobuf.WellKnownTypes.Empty());
        
        return new ClubConfigDto
        {
            ActivationFee = response.ActivationFee,
            MembershipGiftValue = response.MembershipGiftValue
        };
    }
    
    /// <summary>
    /// دریافت لیست فیچرهای باشگاه برای کاربر جاری
    /// </summary>
    public async Task<List<ClubFeatureDto>> GetClubFeaturesAsync()
    {
        var response = await _client.GetClubFeaturesAsync(new Google.Protobuf.WellKnownTypes.Empty());
        
        return response.Features.Select(f => new ClubFeatureDto
        {
            Id = f.Id,
            Title = f.Title,
            Description = f.Description,
            IsEnabled = f.IsEnabled,
            DisplayOrder = f.DisplayOrder,
            GrantedAt = f.GrantedAt?.ToDateTime(),
            CreatedAt = f.CreatedAt?.ToDateTime(),
            Notes = f.Notes
        }).ToList();
    }
}

public class ClubConfigDto
{
    public long ActivationFee { get; set; }
    public long MembershipGiftValue { get; set; }
}

public class ClubFeatureDto
{
    public long Id { get; set; }
    public string Title { get; set; } = string.Empty;
    public string? Description { get; set; }
    public bool IsEnabled { get; set; }
    public int DisplayOrder { get; set; }
    public DateTime? GrantedAt { get; set; }
    public DateTime? CreatedAt { get; set; }
    public string? Notes { get; set; }
}
