using APT.Infrastructure.Core;
using APT.MS.Domain.ApiModel;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.IServices.FM;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

using APT.Utility;
using APT.BaseData.Domain.ApiModel;

namespace APT.FM.WebApi.Controllers.Api.FM
{
	[Route("api/FM/ImportConfig")]
	public class ImportConfigController : AuthorizeApiController<T_FM_IMPORT_CONFIG>
	{
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("Entities")]
		public JsonActionResult<IEnumerable<T_FM_IMPORT_CONFIG>> Entities([FromBody]KeywordFilter filter)
		{
			return WitEntities(null, filter);
		}
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		/// 

		[HttpPost, Route("OrderEntities")]
		public JsonActionResult<IEnumerable<T_FM_IMPORT_CONFIG>> OrderEntities([FromBody]KeywordFilter filter)
		{
			return WitOrderEntities(null, filter);
		}
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="pageFilter"></param>
		/// <returns></returns>
		[HttpPost, Route("Paged")]
		public PagedActionResult<T_FM_IMPORT_CONFIG> Paged([FromBody]KeywordPageFilter pageFilter)
		{
			return WitPaged(null, pageFilter);
		}
		/// <summary>
		/// 查询
		/// </summary>
		/// <param name="pageFilter"></param>
		/// <returns></returns>
		[HttpPost, Route("OrderPaged")]
		public PagedActionResult<T_FM_IMPORT_CONFIG> OrderPaged([FromBody]KeywordPageFilter pageFilter)
		{
			//return WitOrderPaged(null, pageFilter);
			return WitOrderPaged(t=>t.ENABLE_STATUS==0, pageFilter);
		}
		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpGet, Route("Delete")]
		public JsonActionResult<bool> Delete(string id)
		{
			return WitDelete(id);
		}

		/// <summary>
		/// 更新
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPost, Route("Update")]
		public JsonActionResult<bool> Update([FromBody]T_FM_IMPORT_CONFIG entity)
		{
			return WitUpdate(entity);
		}

		/// <summary>
		/// 批量删除
		/// </summary>
		/// <param name="ids"></param>
		/// <returns></returns>
		[HttpGet, Route("BatchDelete")]
		public JsonActionResult<bool> BatchDelete(string ids)
		{
			return WitBatchDelete(ids);
		}


		/// <summary>
		/// 获得单条实体数据
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("Get")]
		public JsonActionResult<T_FM_IMPORT_CONFIG> Get([FromBody] KeywordFilter filter)
		{
			return WitEntity(null, filter);
		}

		/// <summary>
		/// 获取导入列信息
		/// </summary>
		/// <param name="filter"></param>
		/// <returns></returns>
		[HttpPost, Route("GetImportConfig")]
		public JsonActionResult<ImportConfigModel> GetImportConfig([FromBody] KeywordFilter filter)
		{
			return SafeExecute<ImportConfigModel>(() =>
			{
				string code = filter.Keyword;
				if (string.IsNullOrEmpty(code))
					throw new Exception("导入配置编号不允许为空");

				var importService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<IFMImportService>();
				return importService.GetImportConfig(filter.OrgId.Value, code);
			});
		}


	}
}
