using FLY.OBJComponents.IService;
using FLY.Thick.Base.Common;
using FLY.Thick.FilmCasting.IService;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;

namespace FLY.Thick.FilmCasting.WebAPI.Controllers
{

    /// <summary>
    /// 动态区 及 运动
    /// </summary>
    public class ThkGaugeController : ApiController
    {
        IThkGaugeService gageService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="gageService"></param>
        public ThkGaugeController(
            IThkGaugeService gageService
            )
        {
            this.gageService = gageService;
        }

        /// <summary>
        /// 获取服务的数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Data GetValue()
        {

            return new Data()
            {
                DynArea = this.gageService.DynArea
            };
        }

        /// <summary>
        /// 扫描
        /// </summary>
        [HttpPost]
        public void Scan()
        {
            gageService.Scan();
        }

        /// <summary>
        /// 停止
        /// </summary>
        [HttpPost]
        public void Stop()
        {
            gageService.Stop();
        }

        /// <summary>
        /// 归零
        /// </summary>
        [HttpPost]
        public void Home()
        {
            gageService.Home();
        }

        /// <summary>
        /// 前进
        /// </summary>
        [HttpPost]
        public void Forward()
        {
            gageService.Forward();
        }

        /// <summary>
        /// 后退
        /// </summary>
        [HttpPost]
        public void Backward()
        {
            gageService.Backward();
        }

        /// <summary>
        /// 运行到targetPos
        /// </summary>
        [HttpPost]
        public void Runto([FromBody] RuntoRequest request)
        {
            gageService.Runto(request.targetPos);
        }
        /// <summary>
        /// Runto 请求
        /// </summary>
        public class RuntoRequest 
        {
            /// <summary>
            /// 目标位置
            /// </summary>
            public int targetPos;
        }
        /// <summary>
        /// 一直前进
        /// </summary>
        [HttpPost]
        public void ForwUntilStop()
        {
            gageService.ForwUntilStop();
        }

        /// <summary>
        /// 一直后退
        /// </summary>
        [HttpPost]
        public void BackwUntilStop() 
        {
            gageService.BackwUntilStop();
        }

        /// <summary>
        /// 数据
        /// </summary>
        public class Data
        {
            /// <summary>
            /// 动态数据集
            /// </summary>
            public DynArea DynArea { get; set; }
        }
    }
    
    

}
