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

using IRaCIS.Core.Infra.EFCore;
using Microsoft.AspNetCore.Mvc;

namespace IRaCIS.Core.Application.Contracts
{
    /// <summary>
    /// 系统QC 问题管理
    /// </summary>	
    [ApiExplorerSettings(GroupName = "Image")]
    public class QCQuestionConfigureService : BaseService, IQCQuestionService
    {
        private readonly IRepository<QCQuestion> _qcQuestionRepository;

        public QCQuestionConfigureService(IRepository<QCQuestion> qcQuestionRepository)
        {
            _qcQuestionRepository = qcQuestionRepository;
        }


        [HttpPost]
        public async Task<List<QCQuestionConfigureView>> GetQCQuestionConfigureList(QCQuestionQuery queryQCQuestionConfigure)
        {

            var QCQuestionQueryable = _qcQuestionRepository
                .WhereIf(!string.IsNullOrWhiteSpace(queryQCQuestionConfigure.QuestionName), t => t.QuestionName.Contains(queryQCQuestionConfigure.QuestionName))
                .WhereIf(!string.IsNullOrWhiteSpace(queryQCQuestionConfigure.Type), t => t.Type.Contains(queryQCQuestionConfigure.Type))
                 .WhereIf(queryQCQuestionConfigure.IsEnable!=null, t => t.IsEnable==queryQCQuestionConfigure.IsEnable)
             .ProjectTo<QCQuestionConfigureView>(_mapper.ConfigurationProvider);

            return await QCQuestionQueryable.ToListAsync();
        }

        public async Task<IResponseOutput> AddOrUpdateQCQuestionConfigure(QCQuestionAddOrEdit addOrEditQCQuestionConfigure)
        {

            var entity = await _qcQuestionRepository.InsertOrUpdateAsync(addOrEditQCQuestionConfigure, true);
            return ResponseOutput.Ok(entity.Id.ToString());
        }


        [HttpDelete("{qCQuestionConfigureId:guid}")]
        public async Task<IResponseOutput> DeleteQCQuestionConfigure(Guid qCQuestionConfigureId)
        {
            var success = await _qcQuestionRepository.BatchDeleteNoTrackingAsync(t => t.Id == qCQuestionConfigureId);
            return ResponseOutput.Result(success);
        }


    }
}