using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
using QuantEngine.Core.Interfaces;
using QuantEngine.Web.Services;

namespace QuantEngine.Web.Pages.Admin.Decisions;

[Authorize(AuthenticationSchemes = AdminAuthDefaults.Scheme)]
public class IndexModel : PageModel
{
    private readonly IPostgresqlHistoryStore _historyStore;

    public IReadOnlyList<IDictionary<string, object?>> Decisions { get; private set; } = Array.Empty<IDictionary<string, object?>>();

    public IndexModel(IPostgresqlHistoryStore historyStore)
    {
        _historyStore = historyStore;
    }

    public async Task OnGetAsync()
    {
        try
        {
            Decisions = await _historyStore.SnapshotAsync("decision_result_history", 100);
        }
        catch
        {
            Decisions = Array.Empty<IDictionary<string, object?>>();
        }
    }
}
