using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Description;
using CncModels.Dto;
using CncModels.Dto.CollectLog;
using CncService.Interface;
using CncWebApi.Infrastructure;
using Newtonsoft.Json;

namespace CncWebApi.Controllers
{
    /// <summary>
    /// 数据回放控制器
    /// </summary>
    [RoutePrefix("api/admin/replay")]
    [JwtAuthFilter]
    public class ReplayController : ApiController
    {
        private readonly IReplayService _replayService;

        public ReplayController(IReplayService replayService)
        {
            _replayService = replayService ?? throw new ArgumentNullException(nameof(replayService));
        }

        /// <summary>预览回放影响范围</summary>
        [HttpPost]
        [Route("preview")]
        [ResponseType(typeof(ApiResponse<ReplayPreview>))]
        public IHttpActionResult Preview([FromBody] ReplayRequest request)
        {
            if (request == null) return BadRequest("请求参数错误");
            var result = _replayService.PreviewReplay(request.Date);
            return Ok(ApiResponse<ReplayPreview>.Success(result));
        }

        /// <summary>执行回放</summary>
        [HttpPost]
        [Route("execute")]
        [ResponseType(typeof(ApiResponse<ReplayResult>))]
        public IHttpActionResult Execute([FromBody] ReplayRequest request)
        {
            if (request == null) return BadRequest("请求参数错误");
            var result = _replayService.ExecuteReplay(request.Date);
            return Ok(ApiResponse<ReplayResult>.Success(result));
        }
    }
}
