using MediatR;
using MiningService.Domain.AggregatesModel.CircleAggregate;

namespace MiningService.API.Application.Queries;

/// <summary>
/// EN: Query to get circle trust score.
/// VI: Query để lấy điểm tin cậy vòng tròn.
/// </summary>
public record GetCircleTrustScoreQuery(Guid UserId) : IRequest<CircleTrustScoreDto?>;

public record CircleTrustScoreDto(
    Guid CircleId,
    string Name,
    int MemberCount,
    decimal TrustScore,
    bool IsValid,
    decimal BonusMultiplier);

public class GetCircleTrustScoreQueryHandler : IRequestHandler<GetCircleTrustScoreQuery, CircleTrustScoreDto?>
{
    private readonly ICircleRepository _circleRepository;

    public GetCircleTrustScoreQueryHandler(ICircleRepository circleRepository)
    {
        _circleRepository = circleRepository;
    }

    public async Task<CircleTrustScoreDto?> Handle(GetCircleTrustScoreQuery request, CancellationToken cancellationToken)
    {
        var circle = await _circleRepository.GetByOwnerIdAsync(request.UserId, cancellationToken);
        if (circle == null) return null;

        return new CircleTrustScoreDto(
            circle.Id,
            circle.Name,
            circle.ActiveMemberCount,
            circle.TrustScore,
            circle.IsValid,
            circle.BonusMultiplier);
    }
}
