using HoneyBox.Admin.Models.Common;
using HoneyBox.Admin.Models.OperationLog;
using HoneyBox.Admin.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace HoneyBox.Admin.Controllers;

/// <summary>
/// 操作日志控制器
/// </summary>
[ApiController]
[Route("api/admin/logs")]
[Authorize]
public class OperationLogController : ControllerBase
{
    private readonly IOperationLogService _operationLogService;
    private readonly ILogger<OperationLogController> _logger;

    public OperationLogController(IOperationLogService operationLogService, ILogger<OperationLogController> logger)
    {
        _operationLogService = operationLogService;
        _logger = logger;
    }

    /// <summary>
    /// 获取操作日志分页列表
    /// </summary>
    /// <param name="request">查询请求</param>
    /// <returns>分页结果</returns>
    [HttpGet]
    public async Task<ApiResponse<PagedResult<OperationLogDto>>> GetList([FromQuery] OperationLogQueryRequest request)
    {
        var result = await _operationLogService.GetListAsync(request);
        return ApiResponse<PagedResult<OperationLogDto>>.Success(result);
    }

    /// <summary>
    /// 获取日志详情
    /// </summary>
    /// <param name="id">日志ID</param>
    /// <returns>日志详情</returns>
    [HttpGet("{id:long}")]
    public async Task<ApiResponse<OperationLogDto>> GetById(long id)
    {
        var result = await _operationLogService.GetByIdAsync(id);
        return ApiResponse<OperationLogDto>.Success(result);
    }
}
