using System;
using Predictalytics.Domain.Entities;

namespace Predictalytics.Domain.Helpers;

public static class MarketOutcomeHelper
{
    public static bool IsWinningOutcome(MarketOutcome outcome, string? resolutionOutcome)
    {
        if (string.IsNullOrWhiteSpace(resolutionOutcome)) return false;
        
        // Exact match
        if (string.Equals(outcome.Label, resolutionOutcome, StringComparison.OrdinalIgnoreCase))
            return true;
            
        // Grouped match (e.g., "Group - Yes" matches "Yes")
        if (outcome.Label.EndsWith(" - " + resolutionOutcome, StringComparison.OrdinalIgnoreCase))
            return true;
            
        // Index match (sometimes resolution is the index "0", "1")
        if (int.TryParse(resolutionOutcome, out var resIndex) && outcome.OutcomeIndex == resIndex)
            return true;

        return false;
    }
}
