using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using EVCB_OCPP.Packet.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EVCB_OCPP.Packet.Messages.SubTypes;
using EVCB_OCPP.Packet.Features;

namespace EVCB_OCPP.Packet.Messages.Core
{
    public class StopTransactionRequest : IRequest
    {

        public StopTransactionRequest()
        {
            Action = Actions.StopTransaction.ToString();
        }

        [JsonIgnore]
        public string Action { set; get; }


        /// <summary>
        /// Authorization Id
        /// </summary>
        public string idTag { set; get; }
        /// <summary>
        /// 充電結束的電表讀數
        /// </summary>
        [Required]
        public int meterStop { set; get; }

        /// <summary>
        /// 交易Id
        /// </summary>
        [Required]
        public int transactionId { set; get; }

        /// <summary>
        /// 結束原因
        /// </summary>
        [JsonConverter(typeof(StringEnumConverter))]
        public Reason? reason { set; get; }
        /// <summary>
        /// 結束交易的時間
        /// </summary>
        [Required]
        [JsonConverter(typeof(UTCDateTimeConverter))]
        public DateTime timestamp { set; get; }

        /// <summary>
        /// 交易資料 (可包含交易細節 & 帳單)
        /// </summary> 
        public List<MeterValue> transactionData { set; get; }

        public bool TransactionRelated()
        {
            return true;
        }

        public bool Validate()
        {
            return Validator.TryValidateObject(this, new ValidationContext(this), null, true);
        }
    }
}
