using Microsoft.AspNetCore.Mvc;
using ms_useCaseService.Mapping;
using webApiGateway.Objects.Objects;

namespace ms_useCaseService.Controllers;

/// <summary>
/// Controller for generating web requests related to use cases.
/// </summary>
[ApiController]
[Route("/data")]
public class WebController : ControllerBase
{
    /// <summary>
    /// Represents the logger instance for this class.
    /// </summary>
    private static ILogger Logger = Logging.LoggerFactory.CreateLogger<WebController>();

    /// <summary>
    /// Returns a list of UseCase objects that match a specified query string.
    /// </summary>
    /// <param name="query">The query string used to retrieve UseCase objects.</param>
    /// <returns>A Task of List of UseCase objects that match the specified query.</returns>
    [HttpGet]
    [Route("/data")]
    public async Task<List<UseCase>> GetUseCases([FromQuery] string query)
    {
        // Log a input query
        Logger.LogInformation("Input query for the use cases: {0}", query);
        
        //Getting the use cases based on the input specified query
        List<UseCase> UseCases = await MainMapping.GetMappedUseCases(query);

        // Return the value of the "UseCases" variable
        return UseCases;
    }

    /// <summary>
    /// Inserts data into a database.
    /// </summary>
    /// <param name="title">The title of the data to insert.</param>
    /// <param name="description">The description of the data to insert.</param>
    /// <param name="tags">The tags associated with the data to insert.</param>
    /// <param name="logsource">The source of the log data.</param>
    [HttpGet]
    [Route("/insert")]
    public void InsertData([FromQuery] string title, string description, string tags, string logsource)
    {
        //Log the inserting data
        Logger.LogInformation("Data to insert - Title: {0}, Description: {1}, Tags: {2}, LogSource: {3}", title, description, tags, logsource);

        //Inserting the data
        Insert.InsertData(title, description, tags, logsource);
    }
}