//--------------------------------------------------------------------
//     此代码由T4模板自动生成  byzhouhang 20210918
//	   生成时间 2022-03-03 15:28:32 
//     对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
//--------------------------------------------------------------------

using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Infra.EFCore;
using Microsoft.AspNetCore.Mvc;
namespace IRaCIS.Core.Application.Service
{
    /// <summary>
    /// SystemAnonymizationService
    /// </summary>	
    [ApiExplorerSettings(GroupName = "Image")]
    public class SystemAnonymizationService(IRepository<SystemAnonymization> _systemAnonymizationRepository) : BaseService, ISystemAnonymizationService
    {


        [HttpPost]
        public async Task<PageOutput<SystemAnonymizationView>> GetSystemAnonymizationList(SystemAnonymizationQuery inQuery)
        {

            var systemAnonymizationQueryable = _systemAnonymizationRepository
                .WhereIf(!string.IsNullOrEmpty(inQuery.Group), t => t.Group.Contains(inQuery.Group))
                .WhereIf(!string.IsNullOrEmpty(inQuery.Element), t => t.Element.Contains(inQuery.Element))
                .WhereIf(inQuery.IsAdd != null, t => t.IsAdd == inQuery.IsAdd)
                .WhereIf(!string.IsNullOrEmpty(inQuery.ValueRepresentation), t => t.ValueRepresentation.Contains(inQuery.ValueRepresentation))
            .ProjectTo<SystemAnonymizationView>(_mapper.ConfigurationProvider);

            return await systemAnonymizationQueryable.ToPagedListAsync(inQuery);
        }


        public async Task<IResponseOutput> AddOrUpdateSystemAnonymization(SystemAnonymizationAddOrEdit addOrEditSystemAnonymization)
        {

            var entity = await _systemAnonymizationRepository.InsertOrUpdateAsync(addOrEditSystemAnonymization, true);


            return ResponseOutput.Ok(entity.Id.ToString());

        }


        [HttpDelete("{systemAnonymizationId:guid}")]
        public async Task<IResponseOutput> DeleteSystemAnonymization(Guid systemAnonymizationId)
        {
            var success = await _systemAnonymizationRepository.BatchDeleteNoTrackingAsync(t => t.Id == systemAnonymizationId);

            return ResponseOutput.Result(success);
        }


    }
}