using Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;

namespace BLW_Log.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TouChuanController : ControllerBase
    {
        public IMemoryCache _cache { get; set; }

        public TouChuanController(IMemoryCache cache)
        {
            this._cache = cache;
        }


        [HttpPost()]
        public async Task<ReturnInfo> SendUDPPackage([FromBody] Dictionary<string, string> L)
        {

            //hostnumber 
            //mac
            //bytelist 命令集，如01020304050a0b
            //cmdtype 命令类型
            //isoriginal  是否原始数据 如果这个为true，就不再遵循RCU的协议规范
            ReturnInfo info = new ReturnInfo();
            info.isok = true;
            try
            {

                ReturnInfo data = await Http.HttpPostFormSendData(L, "api/SendUDPPackage");
                info.response = data;
            }
            catch (Exception ex)
            {
                info.isok = false;
                info.message = ex.Message;
            }
            return info;
        }

        [HttpPost()]
        public async Task<ReturnInfo> SetTouChuanData([FromBody] Dictionary<string, string> L)
        {

            //hostnumber 
            //mac
            //add_or_remove
            ReturnInfo info = new ReturnInfo();
            info.isok = true;
            try
            {

                ReturnInfo data = await Http.HttpPostFormSendData(L, "api/SetTouChuanData");
                info.response = data;
            }
            catch (Exception ex)
            {
                info.isok = false;
                info.message = ex.Message;
            }
            return info;
        }
    }
}
