using FLY.Thick.Base.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace FLY.Thick.FilmCasting.WebAPI.Controllers
{

    public class FixController : ApiController
    {
        IFixService fixService;

        /// <summary>
        /// 
        /// </summary>
        public FixController(
            IFixService fixService
            )
        {
            this.fixService = fixService;
        }

        /// <summary>
        /// 获取服务的设置及状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Data GetValue()
        {

            return new Data()
            {
                UpdateTime = fixService.UpdateTime
            };
        }

        /// <summary>
        /// 获取定点数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<GetFixDatasReponse> GetFixDatas() 
        {
            var tcs = new TaskCompletionSource<GetFixDatasReponse>();

            fixService.GetFixDatas((asyncContext, retData) =>
            {
                var response = retData as GetFixDatasReponse;

                tcs.SetResult(response);

            }, null);

            return await tcs.Task;
        }
        /// <summary>
        /// 
        /// </summary>
        public class Data 
        {
            /// <summary>
            /// FixData更新时间
            /// </summary>
            public DateTime UpdateTime { get; set; }
        }
    }
}
