using System;
namespace Renci.SshNet.Messages.Authentication
{
    /// 
    /// Represents SSH_MSG_USERAUTH_REQUEST message. Server as a base message for other user authentication requests.
    /// 
    [Message("SSH_MSG_USERAUTH_REQUEST", 50)]
    public class RequestMessage : Message
    {
        /// 
        /// Gets authentication username.
        /// 
        public string Username { get; private set; }
        /// 
        /// Gets the name of the service.
        /// 
        /// 
        /// The name of the service.
        /// 
        public ServiceName ServiceName { get; private set; }
        /// 
        /// Gets the name of the authentication method.
        /// 
        /// 
        /// The name of the method.
        /// 
        public virtual string MethodName { get { return "none"; } }
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// Name of the service.
        /// Authentication username.
        public RequestMessage(ServiceName serviceName, string username)
        {
            this.ServiceName = serviceName;
            this.Username = username;
        }
        /// 
        /// Called when type specific data need to be loaded.
        /// 
        protected override void LoadData()
        {
            throw new InvalidOperationException("Load data is not supported.");
        }
        /// 
        /// Called when type specific data need to be saved.
        /// 
        protected override void SaveData()
        {
            this.Write(this.Username);
            switch (this.ServiceName)
            {
                case ServiceName.UserAuthentication:
                    this.WriteAscii("ssh-userauth");
                    break;
                case ServiceName.Connection:
                    this.WriteAscii("ssh-connection");
                    break;
                default:
                    throw new NotSupportedException("Not supported service name");
            }
            this.WriteAscii(this.MethodName);
        }
    }
}