using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Infra.EFCore.Common;
using MassTransit;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Application.Service.Reading.Dto;
using Panda.DynamicWebApi.Attributes;

namespace IRaCIS.Core.Application.Service.TA
{


    [ApiExplorerSettings(GroupName = "Reading")]
    public class ReadingQuestionService : BaseService
    {
        private readonly IRepository<TumorAssessment_RECIST1Point1> _tumorAssessmentRepository1Point1;
        private readonly IRepository<TumorAssessment_IRECIST1Point1> _tumorAssessmentIRepository1Point1;
        private readonly IRepository<TumorAssessment_RECIST1Point1BM> _tumorAssessmentRepository1Point1BM;

        public ReadingQuestionService(      IRepository<TumorAssessment_RECIST1Point1> tumorAssessmentRepository1Point1,
             IRepository<TumorAssessment_IRECIST1Point1> tumorAssessmentIRepository1Point1,
             IRepository<TumorAssessment_RECIST1Point1BM> tumorAssessmentRepository1Point1BM
            )
        {
            this._tumorAssessmentRepository1Point1 = tumorAssessmentRepository1Point1;
            this._tumorAssessmentIRepository1Point1 = tumorAssessmentIRepository1Point1;
            this._tumorAssessmentRepository1Point1BM = tumorAssessmentRepository1Point1BM;
        }


        ///// <summary>
        ///// 获取疗效对照
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //public async Task<List<TumorAssessmentView>> GetTumorAssessmentList(GetTumorAssessmentListInDto inDto)
        //{
        //    var result = await _tumorAssessmentRepository
        //        .Where(x => x.CriterionId == inDto.CriterionId)
        //        .WhereIf(inDto.OverallEfficacy != null, x => x.OverallEfficacy == inDto.OverallEfficacy)
        //         .WhereIf(inDto.TargetLesion != null, x => x.TargetLesion == inDto.TargetLesion)
        //          .WhereIf(inDto.NonTargetLesions != null, x => x.NonTargetLesions == inDto.NonTargetLesions)
        //           .WhereIf(inDto.NewLesion != null, x => x.NewLesion == inDto.NewLesion)
        //          .ProjectTo<TumorAssessmentView>(_mapper.ConfigurationProvider).ToListAsync();
        //    return result;
        //}

        /// <summary>
        /// 获取疗效对照
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<(object,List<ColumnInfo>)> GetTumorAssessmentPageList(GetTumorAssessmentListInDto inQuery)
        {
            var result = new object();
            List<ColumnInfo> columnList = new List<ColumnInfo>();
            switch (inQuery.CriterionType)
            {
                case CriterionType.RECIST1Point1:
                    result= await _tumorAssessmentRepository1Point1.AsQueryable().ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(TumorAssessmentView.Id) : inQuery.SortField, inQuery.Asc);
                    columnList = new List<ColumnInfo>()
                    {
                        new  ColumnInfo(){ ColumnName="靶病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.TargetLesion),DictionaryKey=typeof(TargetAssessment).Name },
                        new  ColumnInfo(){ ColumnName="非靶病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.NonTargetLesions),DictionaryKey=typeof(NoTargetAssessment).Name },
                        new  ColumnInfo(){ ColumnName="新病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.NewLesion),DictionaryKey=typeof(NewLesionAssessment).Name },
                        new  ColumnInfo(){ ColumnName="整体疗效",ColumnKey=nameof(TumorAssessment_RECIST1Point1.OverallEfficacy),DictionaryKey=typeof(OverallAssessment).Name },
                    };
                    break;
                case CriterionType.RECIST1Pointt1_MB:
                    result = await _tumorAssessmentRepository1Point1BM.AsQueryable().ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(TumorAssessmentView.Id) : inQuery.SortField, inQuery.Asc);
                    columnList = new List<ColumnInfo>()
                    {
                        new  ColumnInfo(){ ColumnName="靶病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.TargetLesion),DictionaryKey=typeof(TargetAssessment).Name },
                        new  ColumnInfo(){ ColumnName="非靶病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.NonTargetLesions),DictionaryKey=typeof(NoTargetAssessment).Name },
                        new  ColumnInfo(){ ColumnName="新病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.NewLesion),DictionaryKey=typeof(NewLesionAssessment).Name },
                        new  ColumnInfo(){ ColumnName="整体疗效",ColumnKey=nameof(TumorAssessment_RECIST1Point1.OverallEfficacy),DictionaryKey=typeof(OverallAssessment).Name },
                    };
                    break;
                case CriterionType.IRECIST1Point1:
                    result = await _tumorAssessmentIRepository1Point1.AsQueryable().ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(TumorAssessmentView.Id) : inQuery.SortField, inQuery.Asc);
                    columnList = new List<ColumnInfo>()
                    {
                        new  ColumnInfo(){ ColumnName="靶病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.TargetLesion),DictionaryKey=typeof(TargetAssessment).Name },
                        new  ColumnInfo(){ ColumnName="非靶病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.NonTargetLesions),DictionaryKey=typeof(NoTargetAssessment).Name },
                        new  ColumnInfo(){ ColumnName="新病灶",ColumnKey=nameof(TumorAssessment_RECIST1Point1.NewLesion),DictionaryKey=typeof(NewLesionAssessment).Name },
                        new  ColumnInfo(){ ColumnName="整体疗效",ColumnKey=nameof(TumorAssessment_RECIST1Point1.OverallEfficacy),DictionaryKey=typeof(OverallAssessment).Name },
                    };
                    break;
            }

            return (result, columnList);

        }


        ///// <summary>
        ///// 新增修改疗效对照
        ///// </summary>
        ///// <param name="indto"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public async Task<IResponseOutput> AddOrUpdateTumorAssessment(AddOrUpdateTumorAssessmentInDto indto)
        //{

        //    var entity = await _tumorAssessmentRepository.InsertOrUpdateAsync(indto, true);

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

        //}

        ///// <summary>
        ///// 删除疗效对照
        ///// </summary>
        ///// <param name="Id"></param>
        ///// <returns></returns>
        //[HttpDelete("{Id:guid}")]
        //public async Task<IResponseOutput> DeleteTumorAssessment(Guid Id)
        //{
        //    await _tumorAssessmentRepository.DeleteFromQueryAsync(t => t.Id == Id);
        //    var success = await _tumorAssessmentRepository.SaveChangesAsync();
        //    return ResponseOutput.Result(success);
        //}

    }
}