using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using Domain;
using Dao;
using RestSharp;

namespace Service.Implement
{
    public class ECO_SettingManager : GenericManagerBase<ECO_Setting>, IECO_SettingMananger
	{
        public int Add(ECO_Setting test)
        {
            return ((Dao.IECO_SettingRepository)(this.CurrentRepository)).Add(test);
        }

        public new void Update(ECO_Setting n)
        {
            ((Dao.IECO_SettingRepository)(this.CurrentRepository)).Update(n);
        }

        public new void UpdateOrSave(ECO_Setting n)
        {
            ((Dao.IECO_SettingRepository)(this.CurrentRepository)).SaveOrUpdate(n);
        }
        private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(ECO_SettingManager));


        public void ECO_Start_Mission(string hotelid, int start_hour, int start_minute, int end_hour, int end_minute, bool IsEnable)
        {
            var client1 = new RestClient(HostManager.Missionsys_Address);
            var request1 = new RestRequest("api/eco_execute", Method.POST);

            logger.Error("启动ECO任务：" + "api/eco_execute");


            request1.AddParameter("hotelid", hotelid);
            request1.AddParameter("start_hour", start_hour);
            request1.AddParameter("start_minute", start_minute);
            request1.AddParameter("end_hour", end_hour);
            request1.AddParameter("end_minute", end_minute);
            request1.AddParameter("enable_trigger", IsEnable);

            client1.ExecuteAsync(request1, (response) =>
            {
                string result = response.Content;
            });
        }


        /// <summary>
        /// 什么时候重置 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="end_hour"></param>
        /// <param name="end_minute"></param>
        /// <param name="IsEnable"></param>
        public void ECO_Reset_Mission(string id, int end_hour, int end_minute, bool IsEnable)
        {
            var client1 = new RestClient(HostManager.Missionsys_Address);
            var request1 = new RestRequest("api/eco_reset", Method.POST);

            logger.Error("ECO_Reset 任务重置：" + "api/eco_reset");


            request1.AddParameter("eco_reset_key", id);
            request1.AddParameter("hour", end_hour);
            request1.AddParameter("minute", end_minute);
            request1.AddParameter("enable_trigger", IsEnable);

            client1.ExecuteAsync(request1, (response) =>
            {
                string result = response.Content;
            });
        }
    }
}
