using DiunaBI.Infrastructure.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DiunaBI.API.Controllers;

[ApiController]
[Route("[controller]")]
[Authorize]
public class TestsController : Controller
{
    private readonly PluginManager _pluginManager;
    private readonly ILogger<LayersController> _logger;
    public TestsController(
        PluginManager pluginManager,
        ILogger<LayersController> logger)
    {
        _pluginManager = pluginManager;
        _logger = logger;
        
    }

    [HttpGet]
    [Route("Ping")]
    [AllowAnonymous]
    public IActionResult Ping()
    {
        var tmp = new
        {
            a = 2,
            b = "test"
        };
        var tmp2 = new
        {
            a = 2,
            b = "test"
        };
        var user = User.Identity;
        _logger.LogInformation("LogTest: OldValue {tmp}, NewValue {tmp2}, ChangedBy: {user}", tmp, tmp2, user?.Name);
        return Ok("Pong");
    }
    [HttpGet]
    [Route("Plugins")]
    [AllowAnonymous]
    public IActionResult GetPlugins()
    {
        var plugins = _pluginManager.GetPluginsCount();
        return Ok(plugins);
    }
}