using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using Utils;

namespace PMS.NetCore.Controllers
{
    /// <summary>
    /// 车牌识别一体机推送车辆信息
    /// </summary>
    [Produces("application/json;charset=UTF-8")]
    [Route("api/AlarmInfoPlate")]
    [ApiController]
    public class AlarmInfoPlateController : BaseController
    {

        /// <summary>
        /// 客户关系
        /// </summary>
        public AlarmInfoPlateController()
        {
            logger = NLog.LogManager.GetCurrentClassLogger();
        }

        /// <summary>
        /// 推送车辆进出信息
        /// </summary>
        /// <param name="caiInOrOutInfo">进出车辆信息</param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        [Route("CarInOrOut")]
        public JsonResult CarInOrOut([FromBody] CaiInOrOut caiInOrOutInfo)
        {
            var response = new Response_AlarmInfoPlate();
            //logger.Info($"【Fdc_pm_ownerAdd】dto:{JsonConvert.SerializeObject(list)}");
            try
            {
                string serialno = caiInOrOutInfo.AlarmInfoPlate.Serialno;
                string license = caiInOrOutInfo.AlarmInfoPlate.Result.PlateResult.License;
                //var errmsg = "";

                //var manager = new fdc_pm_ownerManager();
                //foreach (var dto in list)
                //{

                //}
                //if (errmsg != "")
                //{
                //    return Json(errmsg);
                //}

                //去除重复的业主主键
                //var list1 = list.Where((x, i) => list.FindIndex(z => z.ownerid == x.ownerid) == i).ToList();
                //var list2 = new List<string>();
                //var owneridMsg = "";
                //foreach (var dto in list1)
                //{
                //    var index = list.IndexOf(dto);
                //    var entity = manager.GetById(dto.ownerid);
                //    if (entity != null)
                //    {
                //        owneridMsg += $"第{index + 1}条数据{dto.ownerid }业主编码已存在;";
                //        list2.Add(dto.ownerid);
                //    }

                //}
                //if(owneridMsg.IsNotNullAndEmpty())
                //{
                //    return Json(owneridMsg);
                ////}
                //for (int i = list1.Count - 1; i >= 0; i--)
                //{
                //    var entity = manager.GetById(list1[i].ownerid);
                //    if (entity != null)
                //    {
                //        list1.Remove(list1[i]);
                //    }
                //}

                //int row = 0;
                //if (list1.Count > 0)
                //{
                //    //批量插入
                //    row = manager.Db.Insertable(list1).ExecuteCommand();
                //}
                //else
                //{
                //    row = 1;
                //}



                //logger.Info($"【Fdc_pm_ownerAdd】row:{row}");


                response.info = "Ok";
                response.channelNum = "license";
                return Json(response);

            }
            catch (Exception ex)
            {
                logger.Error(ex);

                response.info = "Ok";
                response.channelNum = "0";
                return Json(response);
            }
        }

    }
}
