using System.Text.Json.Serialization;
using Prospect.Server.Api.Services.CloudScript;

// ["DropsTotal","DeathsTotal","DeathsPlayerTotal","DeathsCreaturesTotal","DeathsOthersTotal","EvacsTotal","DeathsConsecutive","EvacsConsecutive","KillsPlayersTotal","KillsPlayersMax","KillsCreaturesTotal","KillsCreaturesMax","DamagePlayersTotal","DamagePlayersMax","DamageCreaturesTotal","DamageCreaturesMax","ContractsCompletedKorolevTotal","ContractsCompletedOsirisTotal","ContractsCompletedICATotal","ContractsCompletedTotal","MatchDurationMax","MatchDurationAvg","KMarksMatchMax","KMarksMatchTotal","KMarksTotal"]
public class GetPlayerStatisticsRequestsClientRequest
{
    [JsonPropertyName("statistics")]
    public string[] Statistics { get; set; }
}

[CloudScriptFunction("GetPlayerStatisticsRequestsClient")]
public class GetPlayerStatisticsRequestsClientFunction : ICloudScriptFunction<GetPlayerStatisticsRequestsClientRequest, object>
{
    private readonly IHttpContextAccessor _httpContextAccessor;

    public GetPlayerStatisticsRequestsClientFunction(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }

    public Task<object> ExecuteAsync(GetPlayerStatisticsRequestsClientRequest request)
    {
        var context = _httpContextAccessor.HttpContext;
        if (context == null)
        {
            throw new CloudScriptException("CloudScript was not called within a http request");
        }

        // Return each requested statistic with a value so the career screen renders instead
        // of staying blank. Raid stats (kills/deaths/evacs/damage/…) come from the
        // client-hosted raid and aren't tracked server-side, so they report 0 for now.
        var stats = new List<object>();
        foreach (var name in request.Statistics ?? Array.Empty<string>())
        {
            stats.Add(new { statisticName = name, value = 0 });
        }

        return Task.FromResult<object>(new { statistics = stats });
    }
}
