using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using EonaCat.LogStack.Status.Data;
using EonaCat.LogStack.Status.Models;

namespace EonaCat.LogStack.Status.Pages;

public class CertificatesModel : PageModel
{
    private readonly DatabaseContext _db;
    public CertificatesModel(DatabaseContext db) => _db = db;
    public List<CertificateEntry> Certificates { get; set; } = new List<CertificateEntry>();
    public bool IsAdmin { get; set; }

    public async Task OnGetAsync()
    {
        IsAdmin = HttpContext.Session.GetString("IsAdmin") == "true";
        Certificates = await _db.Certificates.OrderBy(c => c.ExpiresAt).ToListAsync();
    }
}
