//--------------------------------------------------------------------
//     此代码由T4模板自动生成  byzhouhang 20210918
//	   生成时间 2022-07-01 15:33:01 
//     对此文件的更改可能会导致不正确的行为，并且如果重新生成代码，这些更改将会丢失。
//--------------------------------------------------------------------
using System;
using IRaCIS.Core.Domain.Share;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;

namespace IRaCIS.Core.Application.ViewModel
{
    /// <summary> TaskConsistentRuleView  列表视图模型 </summary>
    public class TaskConsistentRuleView : TaskConsistentRuleAddOrEdit
    {
        public Guid CreateUserId { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }
        public Guid UpdateUserId { get; set; }

        public UserSimpleInfo AnalysisDoctorUser { get; set; }


        public int? GeneratedSubjectCount { get; set; }



    }


    public class TaskConsistentRuleBasic : TaskConsistentRuleAddOrEdit
    {

    }

    public class ConsistentQuery : PageInput
    {
        [NotDefault]
        public Guid DoctorUserId { get; set; }
        [NotDefault]
        public Guid TaskConsistentRuleId { get; set; }

        //[NotDefault]
        //public Guid TrialReadingCriterionId { get; set; }

    }

    public class GroupConsistentQuery : PageInput
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        [NotDefault]

        public Guid TrialReadingCriterionId { get; set; }
    }

    public class ConsistentConfirmGenerateCommand
    {
        public Guid TaskConsistentRuleId { get; set; }
        [NotDefault]
        public Guid DoctorUserId { get; set; }

        public List<Guid> SubejctIdList { get; set; }
    }


    public class GroupConsistentConfirmGenrateCommand
    {
        [NotDefault]
        public Guid TrialId { get; set; }
        public List<Guid> SubejctIdList { get; set; }
    }

    public class DoctorSelfConsistentSubjectView: ConsistentCommonView
    {

        public string? BlindSubjectCode { get; set; } 

        public List<VisitTaskSimpleDTO> VisitTaskList { get; set; }

    }


    public class ConsistentCommonView
    {
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }

        public String TrialSiteCode { get; set; }
        public string SubjectCode { get; set; }

        public Guid SubjectId { get; set; }

        public bool IsHaveGeneratedTask { get; set; }

        public bool IsReReadingOrBackInfluenceAnalysis { get; set; }
        public int? ValidVisitCount { get; set; }
    }

    public class DoctorGroupConsistentSubjectView: ConsistentCommonView
    {

        public List<VisitTaskGroupSimpleDTO> SubjectTaskVisitList => VisitTaskList.GroupBy(t => new { t.SubjectId, t.VisitTaskNum }).Where(g => g.Count() == 2).Select(g => g.First()).OrderBy(t=>t.VisitTaskNum).ToList();

        public List<VisitTaskGroupSimpleDTO> VisitTaskList { get; set; } = new List<VisitTaskGroupSimpleDTO>();
    }

    public class VisitTaskGroupSimpleDTO
    {
        public Guid TrialId { get; set; }

        public Guid SubjectId { get; set; }


        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }

        public ReadingCategory ReadingCategory { get; set; }

        //任务阅片状态
        public ReadingTaskState ReadingTaskState { get; set; }

        public TaskState TaskState { get; set; }

        public Guid? DoctorUserId { get; set; }
        public Arm ArmEnum { get; set; }


        public Guid? SourceSubjectVisitId { get; set; }
        public Guid? SouceReadModuleId { get; set; }

        public Guid TrialReadingCriterionId { get; set; }

        public string BlindSubjectCode { get; set; } = string.Empty;
        public string BlindTrialSiteCode { get; set; } = string.Empty;

        public bool IsNeedClinicalDataSign { get; set; }
        public bool IsClinicalDataSign { get; set; }
    }

    public class VisitTaskSimpleDTO :VisitTaskGroupSimpleDTO
    {
        public Guid? Id { get; set; }
      

        public string TaskCode { get; set; }

     
        //可以不查询
        public List<VisitTaskSimpleDTO> GlobalVisitTaskList { get; set; }

        //也可以不查询
        public bool IsHaveGeneratedTask { get; set; }






        //public Guid? TaskConsistentRuleId { get; set; }

    }


    //public class DoctorConsistentRuleSubjectView
    //{
    //    public Guid TrialId => VisitTaskList.Select(t => t.TrialId).First();
    //    public Guid SiteId => VisitTaskList.Select(t => t.SiteId).First();

    //    public String TrialSiteCode => VisitTaskList.Select(t => t.TrialSiteCode).First();
    //    public string SubjectCode => VisitTaskList.Select(t => t.SubjectCode).First();

    //    public Guid SubjectId { get; set; }

    //    public bool IsHaveGeneratedTask { get; set; }
    //    public int? ValidTaskCount { get; set; }

    //    public int? ValidVisitCount => VisitTaskList.Select(t => t.TaskName).Distinct().Count();

    //    public List<VisitTaskSimpleView> VisitTaskList { get; set; }

    //    //public List<UserSimpleInfo> HistoryDoctorUserList => VisitTaskList.SelectMany(t => t.RelationDoctorUserList).DistinctBy(t=>t.UserId).ToList();
    //}

    public class InfluenceTaskInfo
    {
        public Guid Id { get; set; }
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }

        public Guid SubjectId { get; set; }

        public Arm ArmEnum { get; set; }
        public string TaskCode { get; set; }

        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }

        public ReadingCategory ReadingCategory { get; set; }

        //任务阅片状态
        public ReadingTaskState ReadingTaskState { get; set; }

        public TaskState TaskState { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;


        public UserSimpleInfo DoctorUser { get; set; }

        public ReReadingOrBackOptType OptType { get; set; }

        /// <summary>
        /// 是否是一致性分析产生
        /// </summary>
        public bool IsAnalysisCreate { get; set; }

        public bool? IsSelfAnalysis { get; set; }

        public string TrialReadingCriterionName { get; set; }

    }


    public class VisitTaskSimpleView
    {
        public Guid Id { get; set; }
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }

        public Guid SubjectId { get; set; }

        public Arm ArmEnum { get; set; }
        public string TaskCode { get; set; }

        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }

        public ReadingCategory ReadingCategory { get; set; }

        //任务阅片状态
        public ReadingTaskState ReadingTaskState { get; set; }

        public TaskState TaskState { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;


        public UserSimpleInfo DoctorUser { get; set; }

        public List<VisitTaskSimpleView> GlobalVisitTaskList { get; set; }

        //[JsonIgnore]
        //public List<UserSimpleInfo> RelationDoctorUserList { get; set; } = new List<UserSimpleInfo>();

        [JsonIgnore]
        public Guid? DoctorUserId { get; set; }
        [JsonIgnore]
        public Guid? TaskConsistentRuleId { get; set; }

        public bool IsHaveGeneratedTask { get; set; }
    }




    ///<summary>TaskConsistentRuleQuery  列表查询参数模型</summary>
    public class TaskConsistentRuleQuery
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        public bool IsSelfAnalysis { get; set; }

        [NotDefault]
        public Guid TrialReadingCriterionId { get; set; }


    }

    ///<summary> TaskConsistentRuleAddOrEdit  列表查询参数模型</summary>
    public class TaskConsistentRuleAddOrEdit
    {
        public Guid? Id { get; set; }
        public bool IsEnable { get; set; }
        public string Note { get; set; } = string.Empty;
        public Guid TrialId { get; set; }
        public int PlanSubjectCount { get; set; }
        public int PlanVisitCount { get; set; }
        public int IntervalWeeks { get; set; }
        public bool IsHaveReadingPeriod { get; set; }
        public bool IsGenerateGlobalTask { get; set; }

        public bool IsSelfAnalysis { get; set; }
        public int BlindSubjectNumberOfPlaces { get; set; }
        public string BlindTrialSiteCode { get; set; } = string.Empty;

        [NotDefault]
        public Guid TrialReadingCriterionId { get; set; }
    }


    public class TaskConsistentRuleBatchAddOrEdit : TaskConsistentRuleAddOrEdit
    {

        public bool IsBatchAdd { get; set; }
    }

}


