using System;
using InABox.Clients;
using InABox.Core;

namespace InABox.Rpc
{
    public class RpcValidateResult : IRpcCommandResult, IValidationData
    {
        
        public ValidationStatus Status { get; set; }

        public Guid UserGuid { get; set; }

        public string? UserID { get; set; }

        public Guid SecurityID { get; set; }

        public Guid SessionID { get; set; }

        public string? Recipient2FA { get; set; }

        public DateTime PasswordExpiration { get; set; }

        public RpcValidateResult()
        {
            UserID = "";
        }

        public void SerializeBinary(CoreBinaryWriter writer)
        {
            writer.Write((int)Status);
            writer.Write(UserGuid);
            writer.Write(UserID ?? string.Empty);
            writer.Write(SecurityID);
            writer.Write(SessionID);
            writer.Write(Recipient2FA ?? string.Empty);
            writer.Write(PasswordExpiration.ToUniversalTime().Ticks);
        }

        public void DeserializeBinary(CoreBinaryReader reader)
        {
            Status = (ValidationStatus)reader.ReadInt32();
            UserGuid = reader.ReadGuid();
            UserID = reader.ReadString();
            SecurityID = reader.ReadGuid();
            SessionID = reader.ReadGuid();
            Recipient2FA = reader.ReadString();
            PasswordExpiration = new DateTime(reader.ReadInt64(), DateTimeKind.Utc).ToLocalTime();
        }

        public string FullDescription() => Status.ToString();
    }
}