using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using eprintServer.Services; using eprintServer.Entities; using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; using Microsoft.AspNetCore.Http; using System; namespace eprintServer.Controllers; [ApiController] [Route("api/[controller]")] [Authorize(Roles = "ADMIN,SUB_ADMIN")] public class TranslationController : ControllerBase { private readonly TranslationService _translationService; public TranslationController(TranslationService translationService) { _translationService = translationService; } [HttpGet("available-languages")] public async Task>> GetAvailableLanguages() { var languages = await _translationService.GetAllAvailableLanguagesAsync(); return Ok(languages); } [HttpGet("active-transaction-languages")] public async Task> GetActiveConfig() { var setting = await _translationService.GetTranslationSettingAsync(); return Ok(setting); } [HttpPut("update-active-languages-translation")] public async Task> UpdateActiveLanguages([FromBody] List selectedTags) { if (selectedTags == null || !selectedTags.Any()) { return BadRequest("At least one language tag must be provided."); } try { var updatedSetting = await _translationService.UpdateActiveLanguagesAsync(selectedTags); return Ok(updatedSetting); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, $"Error saving configuration: {e.Message}"); } } }