using Managing.Application.Abstractions; using Managing.Application.Abstractions.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Managing.Api.Controllers; /// /// Controller for managing application settings and configurations. /// Provides endpoints for setting up default configurations and resetting settings. /// Requires authorization for access and produces JSON responses. /// [ApiController] [Authorize] [Route("[controller]")] [Produces("application/json")] public class SettingsController : BaseController { private readonly ISettingsService _settingsService; /// /// Initializes a new instance of the class. /// /// The service for managing application settings. /// The service for user-related operations. public SettingsController(ISettingsService settingsService, IUserService userService) : base(userService) { _settingsService = settingsService; } /// /// Sets up initial application settings. /// /// A result indicating if the setup was successful. [HttpPost] public async Task> SetupSettings() { try { var result = await _settingsService.SetupSettings(); return Ok(result); } catch (Exception ex) { return StatusCode(500, $"Error setting up settings: {ex.Message}"); } } /// /// Resets all application settings to their default values. /// /// A result indicating if the reset was successful. [HttpDelete] public async Task> ResetSettings() { try { var result = await _settingsService.ResetSettings(); return Ok(result); } catch (Exception ex) { return StatusCode(500, $"Error resetting settings: {ex.Message}"); } } /// /// Creates default configuration for backtesting including Money Management, Strategy, and Scenario /// for the authenticated user. /// /// A result indicating if the default configuration was created successfully. [HttpPost] [Route("create-default-config")] public async Task> CreateDefaultConfiguration() { try { var user = await GetUser(); if (user == null) { return Unauthorized("User not found or authentication failed"); } var result = await _settingsService.CreateDefaultConfiguration(user); return Ok(result); } catch (Exception ex) { return StatusCode(500, $"Error creating default configuration: {ex.Message}"); } } }