using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Enums;
using APT.Infrastructure.Core;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using APT.Utility;namespace APT.PF.WebApiControllers.Api.PF
{
	[Route("api/PF/QueryApp")]
    public class QueryAppController : AuthorizeApiController<T_PF_QUERY_APP>
    {
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("Entities")]
        public JsonActionResult<IEnumerable<T_PF_QUERY_APP>> Entities([FromBody]KeywordFilter filter)
        {
            return WitEntities(null, filter);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("OrderEntities")]
        public JsonActionResult<IEnumerable<T_PF_QUERY_APP>> OrderEntities([FromBody]KeywordFilter filter)
        {
            return SafeExecute<IEnumerable<T_PF_QUERY_APP>>(() =>
            {
                var data = this.GetOrderEntities<T_PF_QUERY_APP>(null, filter); ;
                data.Where(i => i.DATA_TYPE == (int)PFDataTypeEnum.枚举)
                    .ForEach(i => i.DATA_VALUE = DataHelper.EnumToString(i.DATA_VALUE));
                //foreach (var d in data)
                //{
                //    if (d.DATA_TYPE == (int)DataTypeEnum.枚举)
                //    {
                //        d.DATA_VALUE = DataHelper.EnumToString(d.DATA_VALUE);
                //    }
                //}
                return data;
            });
          
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("Paged")]
        public PagedActionResult<T_PF_QUERY_APP> Paged([FromBody]KeywordPageFilter pageFilter)
        {
            return WitPaged(null, pageFilter);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageFilter"></param>
        /// <returns></returns>
        [HttpPost, Route("OrderPaged")]
        public PagedActionResult<T_PF_QUERY_APP> OrderPaged([FromBody]KeywordPageFilter pageFilter)
        {
            return WitOrderPaged(null, pageFilter);
        }
        [HttpPost, Route("Update")]
        public JsonActionResult<bool> Update([FromBody]T_PF_QUERY_APP entity)
        {
            return WitUpdate(entity);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("Delete")]
        public JsonActionResult<bool> Delete(string id)
        {
            return WitDelete(id);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet, Route("BatchDelete")]
        public JsonActionResult<bool> BatchDelete(string ids)
        {
            return WitBatchDelete(ids);
        }
        /// <summary>
        /// 根据ID获得实体数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("Get")]
        public JsonActionResult<T_PF_QUERY_APP> Get([FromBody] KeywordFilter filter)
        {
            return WitEntity(null, filter);
        }

    }
}
