using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wispro.sp.entity
{
    /// <summary>
    /// 绩效事项清单
    /// </summary>
    public class PerformanceItem
    {
        public PerformanceItem()
        {
            ItemStaffs = new HashSet<ItemStaff>();
        }

        /// <summary>
        /// 编号
        /// </summary>
        
        public int Id { get; set; }

        ///// <summary>
        ///// 绩效计算年度
        ///// </summary>
        //public int Year { get; set; }

        ///// <summary>
        ///// 绩效计算月份
        ///// </summary>
        //public int Month { get; set; }

        /// <summary>
        /// 我方文号
        /// </summary>
        public string CaseNo { get; set; }

        /// <summary>
        /// 申请类型
        /// </summary>
        public string ApplicationType { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        public string BusinessType { get; set; }

        /// <summary>
        /// 代理人反馈Memo
        /// </summary>
        public string AgentFeedbackMemo { get; set; }

        /// <summary>
        /// 处理事项
        /// </summary>
        public string DoItem { get; set; }

        /// <summary>
        /// 案件阶段
        /// </summary>
        public string CaseStage { get; set; }

        /// <summary>
        /// 案件系数
        /// </summary>
        public string CaseCoefficient { get; set; }

        /// <summary>
        /// 处理事项系数
        /// </summary>
        public string DoItemCoefficient { get; set; }

        /// <summary>
        /// 前一次OA处理人Id
        /// </summary>
        public int? PreOastaffId { get; set; }

        /// <summary>
        /// 核稿人Id
        /// </summary>
        public int? ReviewerId { get; set; }

        /// <summary>
        /// 客户Id
        /// </summary>
        public int? CustomerId { get; set; }

        /// <summary>
        /// 申请人
        /// </summary>
        public string ApplicationName { get; set; }

        /// <summary>
        /// 处理事项完成日
        /// </summary>
        public DateTime? FinishedDate { get; set; }

        /// <summary>
        /// 定稿日
        /// </summary>
        public DateTime? FinalizationDate { get; set; }

        /// <summary>
        /// 返稿日
        /// </summary>
        public DateTime? ReturnDate { get; set; }

        /// <summary>
        /// 案件类型
        /// </summary>
        public string CaseType { get; set; }

        /// <summary>
        /// 案件状态
        /// </summary>
        public string CaseState { get; set; }

        /// <summary>
        /// 处理事项备注
        /// </summary>
        public string DoItemMemo { get; set; }

        /// <summary>
        /// 处理状态
        /// </summary>
        public string DoItemState { get; set; }

        /// <summary>
        /// 案件名称
        /// </summary>
        public string CaseName { get; set; }

        /// <summary>
        /// 客户期限
        /// </summary>
        public DateTime? CustomerLimitDate { get; set; }

        /// <summary>
        /// 委托日期
        /// </summary>
        public DateTime? EntrustingDate { get; set; }

        /// <summary>
        /// 内部期限
        /// </summary>
        public DateTime? InternalDate { get; set; }

        /// <summary>
        /// 初稿日
        /// </summary>
        public DateTime? FirstDraftDate { get; set; }

        /// <summary>
        /// 备注（发文严重超期是否属客观原因，若为否，请填写原因）
        /// </summary>
        public string OverDueMemo { get; set; }

        /// <summary>
        /// 基础点数
        /// </summary>
        public double? BasePoint { get; set; }

        /// <summary>
        /// 绩效核算状态：
        /// </summary>
        public int? Status { get; set; }

        /// <summary>
        /// 案件状态
        /// </summary>
        public string CaseMemo { get; set; }

        /// <summary>
        /// 按翻译字数计算设定的字数值
        /// </summary>
        public int? WordCount { get; set; }

        /// <summary>
        /// 绩效类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        public virtual Customer Customer { get; set; }

        /// <summary>
        /// 前一次OA处理人
        /// </summary>
        public virtual Staff PreOastaff { get; set; }

        public virtual ICollection<ItemStaff> ItemStaffs { get; set; }

        /// <summary>
        /// 核稿人
        /// </summary>
        public virtual Staff Reviewer { get; set; }

        public virtual CalMonth CalMonth { get; set; }

        public int CalMonthId { get; set; }

        public bool isDanger()
        {
            if (DoItem.ToString() == "新申请")
            {
                DateTime dt1 = DateTime.MinValue;
                if (ReturnDate != null)
                {
                    dt1 = ReturnDate.Value;
                }

                DateTime dt2 = DateTime.MinValue;
                if (CustomerLimitDate != null)
                {
                    dt2 = CustomerLimitDate.Value;
                }
                else
                {
                    if (InternalDate != null)
                    {
                        dt2 = InternalDate.Value;
                    }
                    else
                    {
                        if (EntrustingDate != null)
                        {
                            dt2 = EntrustingDate.Value;
                        }
                    }
                }

                if ((dt1 - dt2).TotalDays > 30)
                {

                    return true;
                }
                else
                {
                    return false;
                }
            }

            return false;
        }
    }
}

