using EVCB_OCPP.Packet20.DataTypes;
using EVCB_OCPP.Packet20.DataTypes.EnumTypes;
using EVCB_OCPP.Packet20.Utilites;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EVCB_OCPP.Packet20.Messages
{
    public class TransactionEventRequest
    {

        /// <summary>
        /// This contains the type of this event. The first
        /// TransactionEvent of a transaction SHALL contain:
        ///"Started" The last TransactionEvent of a transaction
        ///SHALL contain: "Ended" All others SHALL contain:
        ///"Updated"
        /// </summary>
        [Required]
        [JsonConverter(typeof(StringEnumConverter))]
        public TransactionEventEnumType EventType { set; get; }

        /// <summary>
        /// The date and time at which this transaction
        ///event occurred.
        /// </summary>
        [Required]
        [JsonConverter(typeof(UTCDateTimeConverter))]
        public DateTime Timestamp { set; get; }

        /// <summary>
        /// Reason the Charging Station sends this
        ///message to the CSMS
        /// </summary>
        [Required]
        [JsonConverter(typeof(StringEnumConverter))]
        public TriggerReasonEnumType TriggerReason { set; get; }

        /// <summary>
        /// Incremental sequence number, helps with
        ///determining if all messages of a transaction have been
        /// received
        /// </summary>
        [Required]
        public int SeqNo { set; get; }

        /// <summary>
        /// Indication that this transaction event happened
        /// when the Charging Station was offline.Default = false,
        /// meaning: the event occurred when the Charging Station
        /// was online.
        /// </summary>
        public bool? Offline { set; get; }

        /// <summary>
        /// If the Charging Station is able to report the
        ///  number of phases used, then it SHALL provide it.When
        ///  omitted the CSMS may be able to determine the number
        ///  of phases used via device management
        /// </summary>
        public int? NumberOfPhasesUsed { set; get; }

        /// <summary>
        /// The maximum current of the connected cable in
        ///Ampere(A).
        /// </summary>
        public decimal? CableMaxCurrent { set; get; }

        /// <summary>
        /// his contains the Id of the reservation that
        /// terminates as a result of this transaction.
        /// </summary>
        public int? ReservationId { set; get; }

        /// <summary>
        /// Contains transaction specific information
        /// </summary>
        [Required]
        public TransactionType TransactionInfo { set; get; }

        /// <summary>
        /// This contains the identifier for which a
        ///transaction has to be/was started.Is required when the
        /// EV Driver becomes authorized for this transaction.The
        /// IdToken should only be send once in a
        /// TransactionEventRequest for every authorization done
        /// for this transaction.
        /// </summary>
        public IdTokenType IdToken { set; get; }

        /// <summary>
        /// This identifies which evse (and connector) of
        ///the Charging Station is used.
        /// </summary>
        public EVSEType Evse { set; get; }

        /// <summary>
        /// This contains the relevant meter values.
        /// Depending on the EventType of this TransactionEvent the
        /// following Configuration Variable is used to configure the
        ///content:
        ///Started: SampledDataTxStartedMeasurands
        /// Updated: SampledDataTxUpdatedMeasurands
        /// Ended: SampledDataTxEndedMeasurands &
        ///AlignedDataTxEndedMeasurands
        /// </summary>
        public List<MeterValueType> MeterValue { set; get; }
    }
}
