using System;
using System.Web.Http;
using CncModels.Dto;
using CncModels.Dto.Log;
using CncRepository.Interface;
using CncService.Interface;
using CncWebApi.Infrastructure;

namespace CncWebApi.Controllers
{
    /// <summary>
    /// 操作日志控制器
    /// </summary>
    [RoutePrefix("api/admin/log")]
    [JwtAuthFilter]
    public class LogController : ApiController
    {
        private readonly ISystemLogService _systemLogService;
        private readonly IProductionAdjustmentRepository _adjustmentRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        public LogController(ISystemLogService systemLogService, IProductionAdjustmentRepository adjustmentRepository)
        {
            _systemLogService = systemLogService;
            _adjustmentRepository = adjustmentRepository;
        }

        /// <summary>
        /// 系统运行日志（分页）
        /// GET /api/admin/log/system
        /// </summary>
        [HttpGet]
        [Route("system")]
        public IHttpActionResult GetSystemLog([FromUri] SystemLogQuery query)
        {
            if (query == null) query = new SystemLogQuery();
            var result = _systemLogService.GetList(query);
            return Ok(ApiResponse<PagedResult<SystemLogListItem>>.Success(result));
        }

        /// <summary>
        /// 产量修正日志（分页）
        /// GET /api/admin/log/adjustment
        /// </summary>
        [HttpGet]
        [Route("adjustment")]
        public IHttpActionResult GetAdjustmentLog(string targetTable = null, DateTime? startDate = null, DateTime? endDate = null, string keyword = null, int page = 1, int pageSize = 20)
        {
            var result = _adjustmentRepository.GetList(targetTable, startDate, endDate, keyword, page, pageSize);
            return Ok(ApiResponse<PagedResult<CncModels.Entity.ProductionAdjustment>>.Success(result));
        }

        /// <summary>
        /// 导出修正日志（占位，暂返回提示）
        /// GET /api/admin/log/adjustment/export
        /// </summary>
        [HttpGet]
        [Route("adjustment/export")]
        public IHttpActionResult ExportAdjustment(string targetTable = null, DateTime? startDate = null, DateTime? endDate = null, string keyword = null)
        {
            // 导出功能暂不实现，返回提示
            return Ok(ApiResponse<object>.Fail(40001, "导出功能尚未实现"));
        }
    }
}
