using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums;
using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Core;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APT.FM.WebApi.Controllers.Api
{
    [Route("api/FM/FMNotic")]
    public partial class NoticController : AuthorizeApiController<T_FM_NOTICE>
    {
        /// <summary>
        /// 短信发送跑批
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost, Route("SendNote")]
        public JsonActionResult<bool> SendNote([FromBody] KeywordFilter entity)
        {
            return SafeExecute<bool>(() =>
            {
                return true;
            });
        }

        [HttpPost, Route("OrderPagedByNoticType")]
        public JsonActionResult<IEnumerable<T_FM_NOTICE>> OrderPagedByNoticType([FromBody] KeywordFilter filter)
        {
            return SafeExecute<IEnumerable<T_FM_NOTICE>>(() =>
            {
                filter.SelectField.Add("USER_ID");
                var notices = this.GetEntities<T_FM_NOTICE>(null, filter, "Nav_User");
                BaseFilter baseFilter = new BaseFilter(filter.OrgId);
                var users = this.GetEntities< T_FM_USER >(null, baseFilter);
                foreach (var notice in notices)
                {
                    //if (notice.Nav_Person ==null && notice.USER_ID != null)
                    //{
                    //    T_FM_PERSON person = new T_FM_PERSON()
                    //    {
                    //        ORG_ID = filter.OrgId,
                    //        NAME  = users.FirstOrDefault(x=>x.ID == notice.USER_ID).NAME
                    //    };
                    //    notice.Nav_Person = person;
                    //}                 
                }
                return notices;
            });
        }
    }
}
