using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SinochemInternetPlusApp
{
    class ReceiptModel
    {
        public string TrxModeName { get; set; }
        public string TrxTimeStamp { get; set; }
        public string RunningNumber { get; set; }
        public string CardNo { get; set; }

        public string GradeName { get; set; }
        public int NozzleId { get; set; }
        public double PPU { get; set; }
        public double Qty { get; set; }
        public double Amount { get; set; }

        public double DueAmount { get; set; }
        public double DiscountAmount { get; set; }
        public double PayAmount { get; set; }

        public string PayUrl { get; set; }
        public string InvoiceUrl { get; set; }
    }

    static class ReceiptModelBuilder
    {
        public static ReceiptModel BuildReceiptModel(EpsTransaction epsTrx, EpsTransactionMode trxMode)
        {
            ReceiptModel receiptModel = new ReceiptModel();
            if (epsTrx != null)
            {
                var epsTrxModel = epsTrx.Model;

                if(trxMode == EpsTransactionMode.CarPlateMode)
                {
                    receiptModel.TrxModeName = "车牌付";
                }
                else if(trxMode == EpsTransactionMode.ICCardMode)
                {
                    receiptModel.TrxModeName = "IC卡付";
                }
                else if (trxMode == EpsTransactionMode.BasicMode)
                {
                    receiptModel.TrxModeName = "室内付";
                }

                receiptModel.TrxTimeStamp = BuildTrxDateTime(epsTrxModel);
                receiptModel.RunningNumber = epsTrxModel.bill_id;
                receiptModel.CardNo = epsTrxModel.card_no;
                receiptModel.GradeName = epsTrxModel.youpin;
                receiptModel.NozzleId = epsTrxModel.jihao;
                receiptModel.PPU = epsTrxModel.danjia;
                receiptModel.Qty = epsTrxModel.qty;
                receiptModel.Amount = epsTrxModel.amount;
                receiptModel.DueAmount = epsTrxModel.amount;
                if (epsTrxModel.trx_status == EpsTrxStatus.PaymentOk)
                    receiptModel.DiscountAmount = epsTrxModel.amount - epsTrxModel.real_pay_amount;
                receiptModel.PayAmount = epsTrxModel.real_pay_amount;
                receiptModel.PayUrl = epsTrxModel.pay_url;
                receiptModel.InvoiceUrl = epsTrxModel.invoiceUrl;
            }
            else
            {
                // how to handle here? Leave it as default values?
            }

            return receiptModel;
        }
        
        private static string BuildTrxDateTime(EpsTransactionModel epsTrxModel)
        {
            return Utilities.ConvertDateTimeToReadble(Utilities.CombineDateAndTime(epsTrxModel.xf_date, epsTrxModel.xf_time));
        }
    }
}