using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Domain.MoneyManagements;
using Managing.Domain.Strategies;
using Managing.Domain.Scenarios;
using Managing.Domain.Users;
using static Managing.Common.Enums;

namespace Managing.Api.Controllers;

[ApiController]
[Authorize]
[Route("[controller]")]
[Produces("application/json")]
public class SettingsController : BaseController
{
    private readonly ISettingsService _settingsService;

    public SettingsController(ISettingsService settingsService, IUserService userService)
        : base(userService)
    {
        _settingsService = settingsService;
    }

    [HttpPost]
    public ActionResult SetupSettings()
    {
        return Ok(_settingsService.SetupSettings());
    }

    [HttpDelete]
    public async Task<ActionResult<bool>> ResetSettings()
    {
        return Ok(await _settingsService.ResetSettings());
    }

    /// <summary>
    /// Creates default configuration for backtesting including Money Management, Strategy, and Scenario
    /// </summary>
    /// <returns>A result indicating if the default configuration was created successfully</returns>
    [HttpPost]
    [Route("create-default-config")]
    public async Task<ActionResult<bool>> CreateDefaultConfiguration()
    {
        try
        {
            var user = await GetUser();
            if (user == null)
                return Unauthorized("User not found");

            return Ok(await _settingsService.CreateDefaultConfiguration(user));
        }
        catch (Exception ex)
        {
            return StatusCode(500, $"Error creating default configuration: {ex.Message}");
        }
    }
}
