
using EVCB_OCPP.Packet.Messages.Basic;
using EVCB_OCPP.WSServer.Dto;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using SuperWebSocket;
using SuperSocket.SocketBase;

namespace OCPPServer.Protocol
{
    public class ClientData : WebSocketSession<ClientData>
    { /// <summary>
      /// 根據unique id來儲存.取出OCPP Request
      /// </summary>
        public Queue queue = new Queue();

        public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();

        public bool IsPending { set; get; }
        public bool IsCheckIn { set; get; }

        public string ChargeBoxId { set; get; }

        public Guid CustomerId { get; set; }

        public string MachineId { set; get; }

        public bool ISOCPP20 { set; get; }

        public bool ResetSecurityProfile { set; get; }


        public bool IsAC { set; get; }

        #region Billing

        public Dictionary<string,string> UserPrices { set; get; }

        public Dictionary<string, string> UserDisplayPrices { set; get; }

        public List<ChargingPrice> ChargingPrices { set; get; }

        /// <summary>
        /// 電樁顯示費率
        /// </summary>
        public string DisplayPrice { set; get; }

        /// <summary>
        /// 充電費率 以小時計費
        /// </summary>
        public decimal ChargingFeebyHour { set; get; }

        /// <summary>
        /// 停車費率 以小時計費
        /// </summary>
        public decimal ParkingFee { set; get; }

        /// <summary>
        /// 電樁是否計費
        /// </summary>
        public bool IsBilling { set; get; }

        /// <summary>
        /// 收費方式 1: 以度計費 2:以小時計費
        /// </summary>
        public int BillingMethod { set; get; }
       

        /// <summary>
        /// 電樁適用幣別
        /// </summary>
        public string Currency { get; internal set; }

        #endregion

        public string CustomerName { get; set; }


        public string StationName { set; get; }


        public string StationLocation { set; get; }

        public delegate void OCPPClientDataEventHandler<ClientData, String>(ClientData clientdata, String msg);

        public event OCPPClientDataEventHandler<ClientData, String> m_ReceiveData;

        public ClientData()
        {
            IsAC = true;
            IsPending = false;
            IsCheckIn = false;
            ChargeBoxId = SessionID;
            MachineId = SessionID;
            UserPrices = new Dictionary<string, string>();
            UserDisplayPrices = new Dictionary<string, string>();
        }



        /// <summary>
        /// Sends the raw binary data to client.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        public void SendRawData(byte[] data, int offset, int length)
        {
            base.Send(data, offset, length);
        }

        //receive data event trigger
        public void ReceiveData(ClientData clientdata, string msg)
        {
            if (m_ReceiveData != null)
                m_ReceiveData(clientdata, msg);
        }

        /// <summary>
        /// Called when [session closed].
        /// </summary>
        /// <param name="reason">The reason.</param>
        protected override void OnSessionClosed(CloseReason reason)
        {
        }

    }
}