using System;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure.Extention;

namespace IRaCIS.Application.Contracts
{
    public class PaymentDTO
    {
        public PageOutput<PaymentModel> CostList { get; set; }=new PageOutput<PaymentModel>();
        public decimal ExchangeRate { get; set; }
    }
    public class PaymentModel
    {
        public Guid Id { get; set; }
        public string RankName { get; set; } = String.Empty;
        public Guid DoctorId { get; set; }
        public string YearMonth { get; set; } = String.Empty;
        public DateTime YearMonthDate { get; set; }
        public DateTime? CalculateTime { get; set; }
        public string CalculateUser { get; set; } = String.Empty;

        //额外信息
        public string Code { get; set; } = String.Empty;
        public string FirstName { get; set; } = String.Empty;
        public string LastName { get; set; } = String.Empty;

        public string ChineseName { get; set; } = String.Empty;
        public string Phone { get; set; } = String.Empty;
        public string DoctorNameInBank { get; set; } = String.Empty;
        public string IDCard { get; set; } = String.Empty;
        public string BankCardNumber { get; set; } = String.Empty;
        public string BankName { get; set; } = String.Empty;

        public bool IsLock { get; set; } = false;

        public decimal ExchangeRate { get; set; }

        public decimal PaymentCNY { get; set; }

        public decimal AdjustPaymentCNY { get; set; }
        public decimal TotalPaymentCNY { get; set; }
        public decimal PaymentUSD { get; set; }

        public decimal AdjustPaymentUSD { get; set; }
        public decimal TotalPaymentUSD { get; set; }
    }

    public class PaymentCommand
    {
        public Guid Id { get; set; }
        public Guid DoctorId { get; set; }
        public string YearMonth => new DateTime(Year, Month, 1).ToString("yyyy-MM");
        public int Year { get; set; }
        public int Month { get; set; }
        public decimal PaymentUSD { get; set; }
        public DateTime CalculateTime { get; set; }
        public decimal PaymentCNY { get; set; }
        public decimal ExchangeRate { get; set; }
        public string CalculateUser { get; set; } = String.Empty;
    }

    public class MonthlyPaymentQueryDTO : PageInput
    {
        public DateTime StatisticsDate { get; set; }
        public string KeyWord { get; set; } = String.Empty;
        public int? Nation { get; set; }
    }

    public class MonthlyPaymentDetailQuery
    {
        public Guid PaymentId { get; set; }
        public Guid ReviewerId { get; set; }

        public DateTime YearMonth { get; set; }
    }

    //public class LaborPaymentQuery
    //{
    //    public Guid PaymentId { get; set; }
    //    public Guid ReviewerId { get; set; }

    //    public DateTime YearMonth { get; set; }
    //}


    public class TrialAnalysisDTO
    {
        public Guid TrialId { get; set; }
        public string Indication { get; set; } = String.Empty;

        public string TrialCode { get; set; } = String.Empty;
        public string Cro { get; set; } = string.Empty;

        public int Expedited { get; set; }

        public string Type { get; set; } = String.Empty;

        public decimal PaymentUSD { get; set; }
        public decimal RevenusUSD { get; set; }
        public decimal GrossProfit => RevenusUSD - PaymentUSD;
        public decimal GrossProfitMargin
        {
            get {
                if (RevenusUSD == 0)
                    return 0;
                else
                {
                    return GrossProfit / RevenusUSD;
                }
            }
        }

    }

    public class LaborPayment
    {
        public string ChineseName { get; set; } = String.Empty;
        public string FirstName { get; set; } = String.Empty;
        public string LastName { get; set; } = String.Empty;

        public string ResidentId { get; set; } = String.Empty;

        public string Phone { get; set; } = String.Empty;

        public string AccountNumber { get; set; } = String.Empty;

        public string Bank { get; set; } = String.Empty;
        public string YearMonth { get; set; } = String.Empty;

        public decimal PaymentCNY { get; set; }
        public decimal TaxCNY { get; set; }
        public decimal ActuallyPaidCNY { get; set; }
        public decimal BankTransferCNY { get; set; }
    }
    public class ReviewerAnalysisDTO
    {
        public List<string> MissingTrialCodes = new List<string>();
        public string ChineseName { get; set; } = String.Empty;
        public string FirstName { get; set; } = String.Empty;
        public string LastName { get; set; } = String.Empty;

        public Guid ReviewerId { get; set; }
        public string ReviewerCode { get; set; } = String.Empty;

        public decimal PaymentUSD { get; set; }
        public decimal RevenusUSD { get; set; }
        public decimal GrossProfit => RevenusUSD - PaymentUSD;
       
        public decimal GrossProfitMargin
        {
            get {
                if (RevenusUSD == 0)
                    return 0;
                else
                {
                    return GrossProfit / RevenusUSD;
                }
            }
        }
    }
    public class AnalysisQueryDTO
    {
        public string Reviewer { get; set; } = String.Empty;
        public DateTime BeginDate { get; set; }
        public DateTime EndDate { get; set; }

        public int? Nation { get; set; }
    }

    public class TrialAnalysisQueryDTO
    {
        public Guid? CroId { get; set; }
        public string TrialCode { get; set; } = String.Empty;
        public DateTime BeginDate { get; set; }
        public DateTime EndDate { get; set; }

        public AttendedReviewerType? AttendedReviewerType { get; set; }
    }
}