using adas_core.Application.Services.Interfaces;
using adas_core.Authentication.Attributes;
using adas_core.Domain.Enums;
using adas_core.Logging;
using Microsoft.AspNetCore.Mvc;

namespace adas_core.Controllers;

[Route("service-configs")]
[ApiController]
public class ServiceConfigController : ControllerBase
{
    private readonly IServiceConfigService _serviceConfigService;

    public ServiceConfigController(IServiceConfigService serviceConfigService)
    {
        LogExecutionContext.TrySetTraceIdentifier(Guid.NewGuid().ToString(), true);

        _serviceConfigService = serviceConfigService;
    }

    /// <summary>
    /// Retrieves a service configuration by its identifier. Access is restricted to users with the AuthAdmin role.
    /// </summary>
    /// <param name="id">The unique identifier of the service configuration to retrieve.</param>
    /// <returns>An <see cref="IActionResult"/> containing the requested service configuration.</returns>
    [HttpGet("{id}")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthAdmin)]
    public async Task<IActionResult> Find(string id)
    {
        var serviceConfig = await _serviceConfigService.Get(id);
        return Ok(serviceConfig);
    }
}