using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Watcher.Data;
using Watcher.Models;
using Watcher.ViewModels;

namespace Watcher.Controllers;

[Authorize]
public class ContainerController : Controller
{
    private readonly AppDbContext _context;

    public ContainerController(AppDbContext context)
    {
        _context = context;
    }

    public async Task<IActionResult> Overview()
    {
        // Container mit Server-Informationen laden und nach Server sortieren
        var containers = await _context.Containers
            .Include(c => c.Server)
            .OrderBy(c => c.Server.Name)
            .ThenBy(c => c.Name)
            .ToListAsync();

        var servers = await _context.Servers.ToListAsync();

        var viewModel = new ContainerOverviewViewModel
        {
            Servers = servers,
            Containers = containers
        };

        return View(viewModel);
    }

}
