using Managing.Api.Models.Requests; using Managing.Application.Abstractions.Services; using Managing.Domain.Accounts; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Managing.Api.Controllers { /// /// Provides endpoints for account management operations such as creating, retrieving, and deleting accounts. /// Requires authorization for access. /// [Authorize] public class AccountController : BaseController { private readonly IAccountService _AccountService; /// /// Initializes a new instance of the class. /// /// Service for account-related operations. /// Service for user-related operations. public AccountController( IAccountService AccountService, IUserService userService) : base(userService) { _AccountService = AccountService; } /// /// Creates a new account for the authenticated user. /// /// The account details to create. /// The created account details. [HttpPost] public async Task> PostAccount(Account Account) { var user = await GetUser(); return Ok(await _AccountService.CreateAccount(user, Account)); } /// /// Retrieves all accounts associated with the authenticated user. /// /// A list of accounts. [HttpGet] [Route("accounts")] public async Task>> GetAccounts() { var user = await GetUser(); return Ok(_AccountService.GetAccountsByUser(user, true)); } /// /// Retrieves the balances of all accounts associated with the authenticated user. /// /// A list of accounts with their balances. [HttpGet] [Route("balances")] public async Task>> GetAccountsBalances() { var user = await GetUser(); return Ok(_AccountService.GetAccountsBalancesByUser(user)); } /// /// Retrieves a specific account by name for the authenticated user. /// /// The name of the account to retrieve. /// The account details if found. [HttpGet] public async Task> GetAccount(string name) { var user = await GetUser(); return Ok(await _AccountService.GetAccountByUser(user, name, true, true)); } /// /// Retrieves the GMX claimable fees summary for a specific account. /// /// The name of the account to get claimable fees for. /// The GMX claimable fees summary including funding fees, UI fees, and rebate stats. [HttpGet] [Route("{name}/gmx-claimable-summary")] public async Task> GetGmxClaimableSummary(string name) { var user = await GetUser(); var result = await _AccountService.GetGmxClaimableSummaryAsync(user, name); return Ok(result); } /// /// Swaps tokens on GMX for a specific account. /// /// The name of the account to perform the swap for. /// The swap request containing ticker symbols, amount, and order parameters. /// The swap response with transaction details. [HttpPost] [Route("{name}/gmx-swap")] public async Task> SwapGmxTokens(string name, [FromBody] SwapTokensRequest request) { var user = await GetUser(); var result = await _AccountService.SwapGmxTokensAsync( user, name, request.FromTicker, request.ToTicker, request.Amount, request.OrderType, request.TriggerRatio, request.AllowedSlippage ); return Ok(result); } /// /// Sends tokens from a specific account to a recipient address. /// /// The name of the account to send tokens from. /// The token sending request containing recipient address, ticker, and amount. /// The transaction response with details. [HttpPost] [Route("{name}/send-token")] public async Task> SendToken(string name, [FromBody] SendTokenRequest request) { var user = await GetUser(); var result = await _AccountService.SendTokenAsync( user, name, request.RecipientAddress, request.Ticker, request.Amount, request.ChainId ); return Ok(result); } /// /// Deletes a specific account by name for the authenticated user. /// /// The name of the account to delete. /// An ActionResult indicating the outcome of the operation. [HttpDelete] public async Task DeleteAccount(string name) { var user = await GetUser(); return Ok(_AccountService.DeleteAccount(user, name)); } } }