All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 4s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 11m18s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Successful in 17s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using BCards.Web.Areas.Support.Models;
|
|
using BCards.Web.Configuration;
|
|
using BCards.Web.Models;
|
|
using BCards.Web.Repositories;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace BCards.Web.Areas.Support.Services;
|
|
|
|
public class SupportService : ISupportService
|
|
{
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IOptions<SupportSettings> _settings;
|
|
private readonly ILogger<SupportService> _logger;
|
|
|
|
public SupportService(
|
|
IUserRepository userRepository,
|
|
IOptions<SupportSettings> settings,
|
|
ILogger<SupportService> logger)
|
|
{
|
|
_userRepository = userRepository;
|
|
_settings = settings;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<SupportOptions> GetAvailableOptionsAsync(string? userId)
|
|
{
|
|
var options = new SupportOptions
|
|
{
|
|
CanRate = _settings.Value.EnableRatingForAllUsers,
|
|
CanUseContactForm = false,
|
|
CanAccessTelegram = false,
|
|
TelegramUrl = _settings.Value.TelegramUrl,
|
|
FormspreeUrl = _settings.Value.FormspreeUrl,
|
|
UserPlan = "Trial"
|
|
};
|
|
|
|
// Usuário não autenticado ou trial
|
|
if (string.IsNullOrEmpty(userId))
|
|
{
|
|
_logger.LogDebug("Usuário não autenticado - apenas rating disponível");
|
|
return options;
|
|
}
|
|
|
|
try
|
|
{
|
|
var user = await _userRepository.GetByIdAsync(userId);
|
|
if (user == null)
|
|
{
|
|
_logger.LogWarning("Usuário {UserId} não encontrado", userId);
|
|
return options;
|
|
}
|
|
|
|
var planName = user.CurrentPlan?.ToLower() ?? "trial";
|
|
options.UserPlan = planName;
|
|
|
|
_logger.LogDebug("Verificando opções de suporte para usuário {UserId} com plano {Plan}", userId, planName);
|
|
|
|
// Trial: apenas rating
|
|
if (planName == "trial")
|
|
{
|
|
_logger.LogDebug("Plano Trial - apenas rating disponível");
|
|
return options;
|
|
}
|
|
|
|
// Básico: rating + formulário
|
|
if (planName == "basic" || planName == "básico")
|
|
{
|
|
options.CanUseContactForm = true;
|
|
options.UserPlan = "Básico";
|
|
_logger.LogDebug("Plano Básico - rating + formulário disponíveis");
|
|
return options;
|
|
}
|
|
|
|
// Profissional: rating + formulário (sem telegram)
|
|
if (planName == "professional" || planName == "profissional")
|
|
{
|
|
options.CanUseContactForm = true;
|
|
options.UserPlan = "Profissional";
|
|
_logger.LogDebug("Plano Profissional - rating + formulário disponíveis");
|
|
return options;
|
|
}
|
|
|
|
// Premium e PremiumAffiliate: tudo
|
|
if (planName == "premium" || planName == "premiumaffiliate" || planName == "premium+afiliados")
|
|
{
|
|
options.CanUseContactForm = true;
|
|
options.CanAccessTelegram = true;
|
|
options.UserPlan = planName.Contains("affiliate") || planName.Contains("afiliados") ? "Premium+Afiliados" : "Premium";
|
|
_logger.LogDebug("Plano {Plan} - todas as opções disponíveis", planName);
|
|
return options;
|
|
}
|
|
|
|
return options;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Erro ao verificar opções de suporte para usuário {UserId}", userId);
|
|
return options;
|
|
}
|
|
}
|
|
}
|